我该如何在java中做到这一点?
我需要子类中的构造函数来调用父类(super class)中继承的构造函数。为了做到这一点,我需要使用特殊的语法吗?
我使用了扩展来继承 Person 类。我将如何使用 super() ?
这是我的类(class):
public class Student extends Person
{
protected int id;
public Student()
{
// how do i call the inherited constructor here?
}
}
最佳答案
super(arg1、arg2等);
在任何未显式调用的构造函数的开头都会隐式调用 super()
(不带参数)。
关于java - java中的构造函数调用继承的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8335317/