educative.io

Explanation of question 4


Type your question above this line.

Course: https://www.educative.io/collection/5307417243942912/5730192894984192
Lesson: https://www.educative.io/collection/page/5307417243942912/5730192894984192/5680163505307648

Hi @Shubham_Modi,

  • If no constructor is in the parent class, a Default Constructor (added by the compiler) will be called. But if the parent class has a parameterized constructor, then there is no default constructor and so you get your error.

  • The compiler will add a default constructor when code is compiled but when you declared a parameterized constructor in code, the default constructor will be omitted.

  • When the default constructor is overloaded with the parameterized constructor, It is necessary to have a default constructor in code when you create an object using the default constructor instead of the parameterized constructor.