java中调用继承构造函数的构造函数
我将如何在java中实现这一点 我需要子类中的构造函数来调用超类中继承的构造函数。我需要使用一种特殊的语法来实现这一点吗 我使用扩展从Person类继承。如何使用super() 这是我的班级:java中调用继承构造函数的构造函数,java,class,inheritance,constructor,super,Java,Class,Inheritance,Constructor,Super,我将如何在java中实现这一点 我需要子类中的构造函数来调用超类中继承的构造函数。我需要使用一种特殊的语法来实现这一点吗 我使用扩展从Person类继承。如何使用super() 这是我的班级: public class Student extends Person { protected int id; public Student() { // how do i call the inherited constructor here? } } super(a
public class Student extends Person
{
protected int id;
public Student()
{
// how do i call the inherited constructor here?
}
}
super(arg1、arg2等)代码>
在任何未显式调用的构造函数的开头都有一个对super()
(无参数)的隐式调用。super(arg1、arg2等)代码>
在任何未显式调用的构造函数的开头,都有一个对super()
(无参数)的隐式调用。与此完全相同:super()
。但是我假设您需要调用带有参数的方法,因为存在对super()
的隐式调用。添加参数,如下所示:super(arg0、arg1、arg2等)代码>完全一样:super()
。但是我假设您需要调用带有参数的方法,因为存在对super()
的隐式调用。添加参数,如下所示:super(arg0、arg1、arg2等)代码>