问答详情
源自:10-1 Java 中的多态

请问是哪个地方出问题了,一直是这个错误,应该怎么修改

class Employee{
  private String name;
  private int salary;
  public Employee(String name,int salary){
    this.name=name;
    this.salary=salary;
  }
  public String getDtetails(){
    return"Name:"+name+"\nSalary:"+salary;
  }
}
//定义Employee的子类Manager
class Manager extends Employee{
  private String department;
  public Manager(String name,int salary,String department){
    super(name,salary);//调用父类Employee的构造方法
    this.department=department;
  }
  public String getDetails(){
    //调用父类的成员方法
   return super.getDetails()+"\nDepartment:"+department;
  }
}
public class TestSuper{
 public static void main(String[]args){
    Manager m=new Manager("Tom",2000,"Finance");
    System.out.println(m.getDetails());
  }
}//img4.mukewang.com/59eff2a60001b10004430175.jpg

提问者:慕侠8183234 2017-10-25 10:12

个回答

  • 慕慕4622358
    2017-10-25 11:22:25
    已采纳

    我把你的代码复制到eclipse中运行了一下,发现只是少写了一个字母,改好就能运行了

    //调用父类的成员方法
       return super.getDetails()+"\nDepartment:"+department;

    就上面部分getDetails()方法少了一个字母t,应该是getDtetails()

    结果:

    //img3.mukewang.com/59f003530001a97602350133.jpg