The super keyword in java is a reference variable that is used to refer parent class objects. The keyword “super” came into the picture with the concept of Inheritance. Basically this form of super is used to initialize superclass variables when there is no constructor present in superclass. On the other hand, it is generally used to access the specific variable of a superclass.
Maximum Speed: 120
The super keyword can also be used to access the parent class constructor by adding ‘()’ after it, i.e. super(). One more important thing is that ‘super()’ can call both parametric as well as non-parametric constructors depending upon the situation.
Person class Constructor Student class Constructor
Difference between super and super()
|The super keyword in Java is a reference variable that is used to refer parent class objects.||The super() in Java is a reference variable that is used to refer parent class constructors.|
|super can be used to call parent class’ variables and methods.||super() can be used to call parent class’ constructors only.|
|The variables and methods to be called through super keywordd can be done at any time,||Call to super() must be first statement in Derived(Student) Class constructor.|
|If one does not explicitly invoke a superclass variables or methods, by using super keyword, then nothing happens||If a constructor does not explicitly invoke a superclass constructor by using super(), the Java compiler automatically inserts a call to the no-argument constructor of the superclass.|
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Difference between super() and this() in java
- Difference between Super Key and Candidate Key
- Difference between Primary key and Super key
- Super Keyword in Java
- super and this keywords in Java
- Accessing Grandparent’s member in Java using super
- Difference between an Integer and int in Java with Examples
- Difference between Abstraction and Encapsulation in Java with Examples
- Difference between Java and Kotlin in Android with Examples
- Difference between Iterator and Enumeration in Java with Examples
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.