一段代码- /**练习:写一个员工 ,经理的类继承关系*/
- abstract class Employee
- {
- private String name;
- private String id;
- private int salary;
- Employee(String name,String id,int salary)
- {
- this.name = name;
- this.id = id;
- this.salary = salary;
- }
- abstract void work();
- }
- class Manager extends Employee
- {
- private int bonus;
- Manager(String name,String id,int salary,int bonus)
- {
- super(name,id,salary);
- this.bonus = bonus;
- }
- void work()
- {
- System.out.println("Manager Job");
- }
- }
- class Pro extends Employee
- {
- Pro(String name,String id,int salary)
- {
- super(name,id,salary);
- }
- void work()
- {
- System.out.println("Pro Job");
- }
- }
- class Exam
- {
- public static void main(String[] args)
- {
- System.out.println("Hello World!");
- new Manager("lli","12",2,12).work();
- new Pro("lasdfi","32",3).work();
- }
- }
复制代码
|
|