0
class Person { 
    Person() { 
        System.out.println("This is person class"); 
    } 
} 

class Student extends Person {
    Student() {
        super();
        System.out.println("This is student class");
    }
}
    
class Test { 
    Student s = new Student();
}

The output is

This is person class
This is student class

But if I comment super() call in child class constructor, output is coming same, is it like, giving super() in child class is explicit call to a constructor?

IQbrod
  • 2,060
  • 1
  • 6
  • 28
Kavita Kulkarni
  • 193
  • 2
  • 4
  • 12
  • 1
    Exactly - if there is a default super constructor, i.e. one with an empty parameter list, it is implicitly called unless you specify a different one. – Hulk Jan 22 '21 at 12:39
  • so if I have a parameterized constructor, then I will have to give explicit call in child class constructor to super() with respective parameters? @Hulk – Kavita Kulkarni Jan 22 '21 at 12:43
  • Yes, that is correct. – Hulk Jan 22 '21 at 12:45

0 Answers0