构造函数在java中调用继承的构造函数

时间:2011-12-01 01:02:22

标签: java class inheritance constructor super

我将如何在java中执行此操作?

我需要子类中的构造函数来调用我的超类中的继承构造函数。是否有一个特殊的语法,我需要使用它来做到这一点?

我使用extends来继承Person类。我将如何使用super()?

这是我的班级:

public class Student extends Person
{
   protected int id;

   public Student()
   {
   // how do i call the inherited constructor here?
   }

}

2 个答案:

答案 0 :(得分:3)

super(arg1, arg2, etc);

在任何未明确调用它的构造函数的开头都有对super()(没有参数)的隐式调用。

答案 1 :(得分:0)

完全相同:super()。但是我假设您需要使用参数调用方法,因为对super()进行了隐式调用。添加参数,如下所示:super(arg0, arg1, arg2, etc);

相关问题