Super keyword in Java

Some properties of Super keyword:

  • If you have “childclass” overriding methods in “parentclass”, you can invoke overriden methods using super keyword
  • It has advantage so that you don’t to have to perform operations in the “parentclass” again.
  • Only the immediate “parentclass’s” data and methods can be accessed.

Example:


public class Parentclass {
public void calculateValue() {
System.out.println("2*2");
}
}
public Baseclass extends Parentclass{
// Overrides the calculateValue() method
public void calculateValue() {
super.calculateValue();
System.out.println("10*10");
}
}

Solution:
It will print 4 & 100.