继承问题
class Empolyee{private String name;
private int salary;
public Empolyee(String name,int salary){
this.name = name;
this.salary = salary;
}
public String getDetails(){
return "Name:"+name+"\nsalary:"+salary;
}
}
class Manager extends Empolyee{
private String department;
public Manager(String name,int salary,String department){
super(name,salary);
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,"Finace");
System.out.println(m.getDetails());
}
}
manager是不能继承Empolyee中name和salary的,也就是说manager中的属性只有一个:department。但结果为什么却显示了name和salary属性