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

标签 java class inheritance constructor super

我该如何在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/

相关文章:

java - 从 for 循环中的 if 退出 for 循环?

.net - 何时使用集合与多个属性

javascript - 需要帮助通过数组获取类名

c++ - std::async 无法调用 protected 基类方法

java - 根据时间条件确定 Action

java - 如何使用 SwingX 的荧光笔返回不同的渲染器组件?

java - 请放心/Stack Exchange API : Unable to get success response while trying to hit service from Eclipse

java - 使用 Java Desktop.open( FIle f ) 并知道应用程序已完成

c++ - 为什么我不能通过模板访问子类型?

c# - 强制从派生类外部调用基方法