What is the output of the following Java program no. 7?

  1. class Person
  2. {
  3.     public Person()
  4.     {
  5.         System.out.println(“Person class constructor called”);
  6.     }
  7. }
  8. public class Employee extends Person
  9. {
  10.     public Employee()
  11.     {
  12.         System.out.println(“Employee class constructor called”);
  13.     }
  14.     public static void main (String args[])
  15.     {
  16.         Employee e = new Employee();
  17.     }
  18. }

Output

Person class constructor called
Employee class constructor called

Explanation

The super() is implicitly invoked by the compiler if no super() or this() is included explicitly within the derived class constructor. Therefore, in this case, The Person class constructor is called first and then the Employee class constructor is called.