class Employee{
protected String name;
protected double basic;
protected String address;
Employee(String n,double money,String a){
name=n;
basic=money;
address=a;
}
protected void show(){
System.out.println("\n\n经理详细信息");
System.out.println("========================================");
System.out.println("姓名:"+name);
System.out.println("地址:"+address);
System.out.println("薪资:"+basic);
}
}
class Manager extends Employee{
String department;
Manager(String n,double money,String a,String part){
super(n,money,a);
department=part;
}
void show(){
super.show();
System.out.println("部门:"+department);
}
}
class EmployeeTest{
public static void main(String []args){
Manager mgrObj=new Manager("Henry",5500.65,"Sydney","会计部");
mgrObj.show();
}
}
我刚编的没能通过JAVAC他说问题在于父类方法SHOW是保护状态Manager类不能用他,可Manager是Employee的子类啊?
为什么子类不能调用父类的方法呢?
----------------解决方案--------------------------------------------------------
看置顶 看完了你就懂了
----------------解决方案--------------------------------------------------------
这是因为java继承中要求子类继承自父类的方法的作用域必须大于或等于父类方法的作用域,所以这里要在void show()前加上public 或 protected才行
----------------解决方案--------------------------------------------------------