本帖最后由 陈虹旭 于 2012-9-24 11:51 编辑
- abstract class Employee
- {
- private String name;
- private String id;
- private double pay;
- Employee(String name,String id,double pay)
- {
- this.name = name;
- this.id = id;
- this.pay = pay;
- }
- public abstract void work();
- }
- class Professional extends Employee
- {
- Professional(String name,String id,double pay)
- {
- super(name,id,pay);
- }
- public void work()
- {
- System.out.println(this.name+"..."+this.id+"..."+this.pay+"...Professional work");
- }
- }
- class Manager extends Employee
- {
- private int bonus;
- Manager(String name,String id,double pay,int bonus)
- {
- super(name,id,pay);
- this.bonus = bonus;
- }
- public void work()
- {
- System.out.println(this.name+"..."+this.id+"..."+this.pay+"..."+this.bonus+"...Manager work");
- }
- }
- class EmployeeDemo
- {
- public static void main(String[] args)
- {
- Professional p = new Professional("zhangsan","Pro001",1000.00);
- p.work();
- Manager m = new Manager("lisi","Man001",2000.00,500);
- m.work();
- }
- }
复制代码 提示报错:
EmployeeDemo.java:34: name 可以在 Employee 中访问 private
System.out.println(this.name+"..."+this.id+"..."+this.pay+"...Professional work");
为什么会出现可以访问private的错误呢?
我想带在work()方法中得到员工的姓名,工号,工资等属性该如何得到呢?求指点!
|