Master Super Keyword in Java A Comprehensive W3Schools Guide

Robert Jul 13, 2026

Looking for a powerhouse in Java programming? Meet the super keyword, a versatility master that's seen a revamp in Java 5.0 and beyond. It's multifaceted, including uses as a constructor reference, an instance constructor's reference, and a static method reference. Let's dive in, exploring the marvels of Java's super keyword with w3schools as our guiding light.

10 Example of this keyword in Java
10 Example of this keyword in Java

The super keyword in Java is a reference variable that's used to refer to the immediate parent class object. It's a powerful tool that extends beyond just referential use, making it a staple in object-oriented programming. But first, let's understand the basics using w3schools' interactive tutorials and see it in action.

🔥 Java Super Keyword Explained! 🚀
🔥 Java Super Keyword Explained! 🚀

Super Keyword Basics & Inheritance

The super keyword's primary use is in override methods, helping to call the immediate parent class method. It's a lifesaver when you need to access the parent's class method that was overridden by the subclass. Let's explore this with a simple inheritance example from w3schools, where a 'Child' class extends a 'Parent' class:

Java List of Keywords (All Reserved Words) | Complete Java Reference Guide
Java List of Keywords (All Reserved Words) | Complete Java Reference Guide

public class Parent { void show() { System.out.println("This is Parent's show method"); } } public class Child extends Parent { void show() { System.out.println("This is Child's show method"); super.show(); // Calling parent's show method } }

Super vs. this in Inheritance

While this is used to refer to the current class instance, super is for the parent class instance. Both have their roles, and knowing their differences is crucial. In our example, without super.show(), executing child.show() would only display "This is Child's show method". Let's try it using w3schools' Java compiler.

Famous Keywords in Java
Famous Keywords in Java

Now, let's delve deeper into the super keyword's constructor functionalities, enhancing our coding prowess.

Super Keyword in Constructors

The super keyword also plays a crucial role in constructor creation. It facilitates calling the parent class constructor using its name and parameters, provided they match. This helps in the constructor chaining process and ensures successful initialization of the parent class. Let's see how:

Keywords in JAVA
Keywords in JAVA

Super Constructor Reference

Using the super keyword, you can invoke a parent class constructor. This is particularly useful when the base class has multiple constructors. Let's experiment with a simple example from w3schools:

public class Parent { int num; Parent(int num) { this.num = num; } } public class Child extends Parent { int num; Child(int num) { super(num); // Calling parent's constructor this.num = num * 2; } }

Overloading Constructors with super

java keywords  you must know
java keywords you must know

What if the base class has multiple constructors, and you want to access the correct one based on your subclass's needs? The super keyword comes to your rescue. Let's explore this with an example from w3schools:

public class Parent { int num; Parent() { this.num = 0; } Parent(int num) { this.num = num; } } public class Child extends Parent { int num; Child() { super(); } // Accessing default parent's constructor Child(int num) { super(num * 2); } // Accessing specific parent's constructor }

The super keyword's versatility doesn't stop at constructors and method calls. It also plays a crucial role in instance and static references, offering more breadth to our coding capabilities.

the key words in this language are used to describe something
the key words in this language are used to describe something
Java Programming
Java Programming
Static Keyword In Java With Examples And Best Practices - JavaTechOnline
Static Keyword In Java With Examples And Best Practices - JavaTechOnline
What Keyword is Used to Create a Package in Java?
What Keyword is Used to Create a Package in Java?
Static keyword in Java (Static class, variable, method and block)
Static keyword in Java (Static class, variable, method and block)
Keywords in Java - Java Reserved Words - TechVidvan
Keywords in Java - Java Reserved Words - TechVidvan
Static Keyword In Java With Examples And Best Practices - JavaTechOnline
Static Keyword In Java With Examples And Best Practices - JavaTechOnline
The new keyword in Java programming language - Codeforcoding
The new keyword in Java programming language - Codeforcoding
Java Keywords
Java Keywords
Super Keyword in Java | Learn Coding
Super Keyword in Java | Learn Coding
Java Exception Keywords
Java Exception Keywords
📘 Must-Know Java Keywords Explained Simply 🔑
📘 Must-Know Java Keywords Explained Simply 🔑
Top Features of Java Every Beginner Should Know ☕🚀
Top Features of Java Every Beginner Should Know ☕🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
the different types of html tags are shown in this screenshote screen graber
the different types of html tags are shown in this screenshote screen graber
GENERICS IN JAVA
GENERICS IN JAVA
core java classes in Pune
core java classes in Pune
What is JAVA?
What is JAVA?
Comprehensive Guide to Java Keywords
Comprehensive Guide to Java Keywords
Features of Java | Java Buzzwords
Features of Java | Java Buzzwords

Super in Instance Constructor & Static Method References

In Java 8 and later, the super keyword evolved to include constructor and static method references. This further solidifies its worth, making it an essential tool for lambda expressions and method references. Let's explore these advanced uses:

Instance Constructor Reference

Using 'double colon' (::), we can create an instance constructor reference, calling a constructor from a parent class in subclasses. Let's experiment with an example from w3schools:

public class Parent { int num; Parent(int num) { this.num = num; } } public class Child extends Parent { int num; Child(int num) { super(num); } // Calling parent's constructor }

The same syntax applies to creating references to static methods.

Static Method Reference

Static method references are another powerful use of the super keyword. To reference a static method of the parent class, simply use the class name and the method name: `super.methodName`. Let's see this in action:

public class Parent { static void show() { System.out.println("This is Parent's show method"); } } public class Child extends Parent { static void test() { super.show(); // Calling parent's static method } }

Test these references using w3schools' interactive Java compiler. Now, let's wrap up our discussion on Java's super keyword and its Various uses with some closing thoughts.

From calling parent methods and constructors to instantiating them and referencing static methods, the super keyword showcases its prowess in enhancing code composition and readability. With w3schools' examples guiding us, we can now confidently use this powerful tool in our Java projects. So, go ahead and give it a try. The world of Java is waiting for your code. Happy coding!