Q:

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

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now