Constructor using super keyword


When class hierarchies are created, in what order are the executors of the hierarchical structures implemented? For example, given a subclass called Y and a superclass called X, was the creator of X executed before Y, or vice versa? The answer is that in a hierarchy, manufacturers perform their tasks according to derivation from superclass to subclass. However, since super () must execute the first statement in a subclass constructor, it is the same whether this command will use super (). If Super () is not used, the default or parameterless constructor of each superclass will be executed. The following program describes when the constructors are executed:

Program
// Demonstrate when constructors are executed.

// Create a super class
class X
{
 X()
 {
  System.out.println("Inside X's constructor ");
 }
}
// Create a subclass by extending class X
class Y extends X
{
 Y()
 {
  System.out.println("Inside Y's constructor ");
 }
}
// Create another subclass by extending Y
class Z extends Y
{
 Z()
 {
  System.out.println("Inside Z's constructor ");
 }
}
public class Main 
{
  public static void main(String[] args) 
  {
    Z obj=new Z();
  }
}

As you can see, the constructors are executed in the order of derivation. If you think about it, it is understandable that manufacturers complete their edits in order of derivation. Since a subclass has no subclass knowledge, any initiation that needs to be made is separate from and probably a prerequisite for any subclass executed. Therefore, it must first complete its implementation.