Q:

Java program to call a superclass constructor from sub/child class

belongs to collection: Java Inheritance Programs

0

Java program to call a superclass constructor from sub/child class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

// 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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java program to call the method with the same name... >>
<< Java program to implement hierarchical inheritance...