一个关于方法重写的问题!!
public class Employee{
String name;
int salary;
public String getDetails()
{
return "name:"+name+"\n"+"Salary:"+salary;
}
}
public class Manager extends Employee{
String department;
public String getDetails()
{
return "Name:"+name+"\n"+"Manage of"+department;
}
}
public class Theword{
public static void main(String[]args){
Employee e=new Employee();
Manager m=new Manager();
如果执行语句e.getDetails 和m.getDetails 会调用不同的方法,可是下面的这个会调用哪个啊 !
Employee e=new Manager();
e.getDetails();
这个语句调用超类还是子类的方法啊!
谢谢!