Super in Java
Super in Java
Super in Java
super() will invoke the constructor of the parent class. Even when you don’t add
super() keyword the compiler will add one and will invoke the Parent Class
constructor. You can also call the parameterized constructor of the Parent Class
class ParentClass
{
public ParentClass()
{
System.out.println("Parent Class default Constructor");
}
}
public class SubClass extends ParentClass
{
public SubClass()
{
//super();
System.out.println("Child Class default Constructor");
}
public static void main(String args[])
{
SubClass s = new SubClass();
}
}
Output: Parent Class default Constructor
Child Class default Constructor