【发布时间】:2011-11-10 02:13:05
【问题描述】:
在创建 java 程序时遇到问题,
子类构造函数通过调用超类的方法抛出错误
代码类似这样:
class Manage
{
public static void main(String[] args)
{
Manager m1 = new Manager ( 35 );
}
}
class Employee
{
int emp_id;
public Employee(int id)
{
this.emp_id = id;
}
public int get_id()
{
return emp_id;
}
}
class Manager extends Employee
{
public Manager(int id )
{
this.emp_id = id ;
}
}
class Engineer extends Employee
{
public Engineer(int id)
{
this.emp_id = id ;
}
}
错误是这样的:
$ javac app.java
app.java:25: cannot find symbol
symbol : constructor Employee()
location: class Employee
{
^
app.java:33: cannot find symbol
symbol : constructor Employee()
location: class Employee
{
^
2 errors
为什么会这样?
【问题讨论】:
标签: java inheritance constructor subclass superclass