构造器复用
创建一个Employee类,属性有(名字,性别,年龄,职位,薪水),提供3个构造方法,可以初始化(⑴)(名字,性别,年龄,职位,薪水),(2)(名字,性别,年龄)(3)(职位,薪水).要求充分复用构造器Hello.java
public class Hello {
public static void main(String[] args) {
}
}
class EMployee{
String name;
char gender;
int age;
String job;
double sal;
// 职位 薪水
public EMployee(String job,double sal) {
this.job = job;
this.sal = sal;
}
// 姓名 性别 年龄
public EMployee(String name,char gender,int age) {
this.name = name;
this.gender = gender;
this.age = age;
}
// 名字 性别 年龄 职位 薪水
public EMployee(String job,double sal,String name,char gender,int age) {
this(name,gender,age);
this.job = job;
this.sal = sal;
}
}