In a class hierarchy, constructors are called in order of derivation, from superclass to subclass.
Here is the source code of the Java Program to Allocate and Initialize Super Class Members Using Constructor. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
Parent(int a, int b)
System.out.println(" the super class constructor");
int z = a + b;
System.out.println("the super class method ");
System.out.println("the sum is "+z);
public class Child extends Parent
System.out.println("the sub class constructor ");
public static void main(String ... a)
Child obj = new Child(10);
$ javac Child.java $ java Child the super class constructor the super class method the sum is 32 the sub class constructor 10
Sanfoundry Global Education & Learning Series – 1000 Java Programs.