【java】员工与经理类

it2023-01-24  55

假如我们在开发一个系统时需要对员工进行建模,员工包含3个属性:姓名、工号以及工资。经理也是员工,除了含有员工的属性外,另外还有一个奖金属性。请使用继承的思想设计出员工类和经理类。要求类中提供必要的方法进行属性访问。

员工类:

public class yuangong { private String name; private int ID; private int salary; public yuangong(String name,int ID,int salary){ this.name = name; this.ID = ID; this.salary = salary; } public String findname(){ System.out.println(name); return name; } public int findID(){ System.out.println(ID); return ID; } public int findsalary(){ System.out.println(salary); return salary; } }

经理类

public class jingli extends yuangong{ private int jiangjin; public jingli(String name, int ID, int salary,int jiangjin) { super(name, ID, salary); this.jiangjin = jiangjin; } public int findjiangjin(){ System.out.println(jiangjin); return jiangjin; } }

测试类:

public class homework3 { public static void main(String[] args) { yuangong a = new yuangong("小花",1001,100000); yuangong b = new yuangong("小黄",1002,200000); yuangong c = new yuangong("小张",1003,300000); jingli k = new jingli("大王",0001,800000,10000); a.findID(); b.findname(); c.findsalary(); k.findjiangjin(); } }
最新回复(0)