Super() in Java

Properties of Super() in Java:

  • Used to invoke “Parentclass” constructor using “Baseclass”
  • Invocation of a superclass constructor must be the first line in the subclass constructor.
  • It supports super(), the superclass with no-argument and with super(parameter list) with parameters
  • Java compiler automatically invokes the no-argument constructor of the superclass.

Example:


public void ParentClass {
String message;
public ParentClass ( String message ){
message = message;
}
}
public void BaseClass extends ParentClass {
String messageTwo;
public BaseClass ( String message, String messageTwo ){
super();
messageTwo = messageTwo;
}
}