package com.itheima;
public class Test3 {
public static void main(String[] args) {
/*3、假如我们在开发一个系统时需要对员工进行建模,
员工包含 3 个属性:姓名、工号以及工资。经理也是员工,除了含有员工的属性外,另为还有一个奖金属性。
请使用继承的思想设计出员工类和经理类。要求类中提供必要的方法进行属性访问。*/
Employee ee1 = new Employee("员工1","员工001",5001);
Employee ee2 = new Employee("员工2","员工002",5002);
Employee ee3 = new Employee("员工3","员工003",5003);
System.out.println(ee1);
System.out.println(ee2);
System.out.println(ee3);
Manager ma = new Manager("经理1", "001", 10000, 20000);
System.out.println(ma);
}
}
//定义员工类
class Employee{
private String name;
private String number;
private double salary;
public Employee() {
super();
}
public Employee(String name, String number, double salary) {
super();
this.name = name;
this.number = number;
this.salary = salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Employee [name=" + name + ", number=" + number + ", salary="
+ salary + "]";
}
}
//定义经理类,继承员工类,并具有特有属性:奖金
class Manager extends Employee{
private double bonus;
public Manager(String name, String number, double salary, double bonus) {
super(name, number, salary);
this.bonus = bonus;
}
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Employee [name=" + super.getName() + ", number=" + super.getNumber() + ", salary="
+ super.getSalary()+ ", bonus=" +bonus+ "]";
}
}
|
|