Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Constructors are not inherited?

I have been learning constructors in Inheritance using Eclipse Juno.

When I press ctrl+O twice in the childClass, It shows inherited members. But I happen to see even the Constructor of super class in the inherited members

But it is said that constructors are not inherited...

Can someone please explain this behaviour?

like image 701
Raghu Kariganur Avatar asked Dec 11 '22 12:12

Raghu Kariganur


1 Answers

Unlike fields, methods, and nested classes ,Constructors are not class members.

From docs of Inheritance

A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.

But why constructor removed from class member ??

like image 139
Suresh Atta Avatar answered Jan 03 '23 03:01

Suresh Atta