The source code to call a superclass constructor from sub/child class is given below. The given program is compiled and executed successfully.
// Java program to call a superclass constructor
// from sub/child class
class Super {
Super() {
System.out.println("Super class constructor called.");
}
}
class Sub extends Super {
Sub() {
super();
System.out.println("Sub class constructor called.");
}
}
public class Main {
public static void main(String[] args) {
Sub obj = new Sub();
}
}
Output:
Super class constructor called.
Sub class constructor called.
Program/Source Code:
The source code to call a superclass constructor from sub/child class is given below. The given program is compiled and executed successfully.
Output: