Constructor Chaining in Java
Constructor Chaining in Java:
Constructor chaining is the process of calling the parent class constructor from the child class constructor.It can be achieved by using super() method.
//this is parent class.
class School
{
School()
{
System.out.println("Parent class Constructor");
}
}
//this is child class.
class Student extends School
{
Student()
{
super();
System.out.println("child class constructor");
}
}
public class Demo {
public static void main(String[] args) {
//creating child class object
Student student=new Student();
}
}
Leave a Comment