0 votes
in JAVA by

If a child class inherits base class then are the constructor of the base class also inherited by the child class?

1 Answer

0 votes
by

If a child class inherits base class then are the constructor of the base class also inherited by the child class?

Constructors are not properties of a class. Hence they cannot be inherited. If one can inherit constructors then it would also mean that a child class can be created with the constructor of a parent class which can later cause referencing error when the child class is instantiated. Hence in order to avoid such complications, constructors cannot be inherited. The child class can invoke the parent class constructor by using the super keyword.

Related questions

0 votes
asked Jan 27, 2020 in TypeScript - JavaScript's Superset by AdilsonLima
0 votes
asked Oct 13, 2020 in JAVA by SakshiSharma
...