定义员工类,具有姓名,年龄,性别属性,并具有构造方法,显示数据方法,定义管理层类,继承员工类,并有自 己的属性:职务,年薪。定义职员类,继承员工类,并有自己的属性:所属部门,月薪。
privateStringname;
privateintage;
privatecharsex;
publicEmployee(){
}
publicEmployee(Stringname,intage,charsex){
super();
this.name=name;
this.age=age;
this.sex=sex;
}
publicStringtoString(){
return"雇员姓名:"+this.name+",年龄:"+this.age+",性别:"+this.sex;
}
//setter、getter略
}
classManagerextendsEmployee{
privateStringjob;
privatedoubleincome;
publicManager(){
}
publicManager(Stringname,intage,charsex,Stringjob,doubleincome){
super(name,age,sex);
this.job=job;
this.income=income;
}
publicStringtoString(){
returnsuper.toString()+",职位:"+this.job+",年薪:"+this.income;
}
}
classStaffextendsEmployee{
privateStringdept;
privatedoublesalary;
publicStaff(){
}
publicStaff(Stringname,intage,charsex,Stringdept,doublesalary){
super(name,age,sex);
this.dept=dept;
this.salary=salary;
}
publicStringtoString(){
returnsuper.toString()+",部门:"+this.dept+",月薪:"+this.salary;
}
//setter、getter略
}
publicclassTestDemo{
publicstaticvoidmain(Stringargs[]){
Employeeea=newManager("张三",30,'男',"总监",200000.0);
Employeeeb=newStaff("李四",25,'女',"业务部",1500.0);
System.out.println(ea);
System.out.println(eb);
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。