You are here: Home / Topics / Program to explain Order of Constructor calling in Inheritance in Java

Program to explain Order of Constructor calling in Inheritance in Java

Filed under: Java on 2023-09-17 07:06:22

//  Program to explain Order of Constructor calling in Inheritance

class   A 
{
A() 
{
 System.out.println("Inside A's constructor.");
}
}

class  B  extends  A 
{
B() 
{
 System.out.println("Inside B's constructor.");
}
}

class  C  extends  B 
{
C() 
{
 System.out.println("Inside C's constructor.");
}
}

class  ConstructorCalling 
{
public static void main(String args[ ]) 
{
 C c = new C();
}
}

 

Output:

Inside A's constructor.
Inside B's constructor.
Inside C's constructor.

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.