tutorial, no_image, java,

Java - no_image

Upendra Upendra Follow Jan 23, 2025 · 1 min read
Java - no_image
Share this

Constructor inherited

Short answer - no, a constructor cannot be inherited. Reasons:

  • Constructors are special and have same name as class name. So if constructors were inherited in child class then child class would contain a parent class constructor which is against the constraint that constructor should have same name as class name
  • A constructor cannot be called as a method. It is called when object of the class is created so it does not make sense of creating child class object using parent class constructor notation. i.e. Child c = new Parent();
  • If constructors can be inherited then it will be impossible to achieving encapsulation. Because by using a super class’s constructor we can access/initialize private members of a class.

https://www.geeksforgeeks.org/constructors-not-inherited-java/
https://stackoverflow.com/questions/18147768/why-constructors-can-not-be-inherited-in-java

credit goes to @swayangjit
Join Newsletter
Get the latest news right in your inbox. We never spam!
Upendra
Written by Upendra Follow
Hi, I am Upendra, the author in Human and machine languages,I don't know to how 3 liner bio works so just Connect with me on social sites you will get to know me better.