简体   繁体   English

可以子类构造函数方法覆盖超类构造函数吗? 的“java”

[英]can subclass constructor method override superclass constructor? “java”

is it possible for subclass constructor method override the superclass constructor? 子类构造函数方法是否可以覆盖超类构造函数? since i got a question - superclass(Student), subclass(BachelorStudent), it ask me constructor method for BachelorStudent class must over-ride the Student class. 因为我有一个问题 - 超类(学生),子类(BachelorStudent),它问我BachelorStudent课程的构造函数方法必须覆盖Student类。 is it the question is having error or something wrong? 问题是有错误还是有问题? tq. TQ。

Constructors are never overriden or inherited. 构造函数永远不会被覆盖或继承。 In fact, they cannot be called virtually. 事实上,它们不能被虚拟称呼。

However, you can create a constructor in the subclass which calls a constructor in the parent class. 但是,您可以在子类中创建一个构造函数,该构造函数在父类中调用构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM