Why are constructors not inherited in java?

后端 未结 12 1291
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 14:24

I am a beginner in java programming language, recently I have studied that constructors can not be inherited in java, Can anyone please explain why<

12条回答
  •  庸人自扰
    2020-11-27 15:21

    Simple answer I observed, You cannot invoke or use constructors of parent class in child class directly but methods of parent class you can use directly in child class.

    In case you have method in child class with same name as in parent class at that time only you need to use "super" keyword to invoke parent class method resolve call ambiguity.

    "To invoke" parent class constructor in child class you always need "super" keyword. So parent class constructors are "not directly available" like parent class methods in child class so we can say constructors can not be inherited.

提交回复
热议问题