Constructor
Title
Question
Can we call sub class constructor from super class constructor?
Java Calling-methods-of-the-superclass 02-03 min 10-20 sec
Answers:
Good day.
There is an way to call the constructor of the super-class using method overriding.
Logically processing your question, the question arises on how to define the constructor in the super-class of the sub-class?
I believe any other way is not possible.
Have a great day ahead.
No, you cannot directly call a subclass constructor from a superclass constructor in most object-oriented programming languages like Java, Python, or C++. The relationship between superclass and subclass does not allow upward invocation (from superclass to subclass), as the superclass is not aware of the specifics of its subclass.
Reference: https://www.scientecheasy.com/2020/06/constructor-in-java.html/
Login to add comment