求JAVA高手,使用抽象类及抽象方法abstract编成!
抽象类及抽象方法abstract设置抽象类:Employee,成员变量:工号,姓名方法包括:构造函数Employee(string,string)设置姓名setName(...
抽象类及抽象方法abstract
设置抽象类:Employee,成员变量:工号,姓名
方法包括:构造函数Employee(string, string)
设置姓名setName()
获得工号getNumber()
获得姓名getName()
抽象方法:获取状态getStatus()
设置子类:FullTimeEmployee和PartTimeEmployee,继承Employee超类,并实现抽象方法getStatus,分别输出"Full-Time"及“Part-Time” 展开
设置抽象类:Employee,成员变量:工号,姓名
方法包括:构造函数Employee(string, string)
设置姓名setName()
获得工号getNumber()
获得姓名getName()
抽象方法:获取状态getStatus()
设置子类:FullTimeEmployee和PartTimeEmployee,继承Employee超类,并实现抽象方法getStatus,分别输出"Full-Time"及“Part-Time” 展开
2个回答
2012-12-22
展开全部
代码很简单,完全可以自己写的,以下代码供参考:
public abstract class Employee {
private String empNo;
private String name;
public Employee(String empNo, String name) {
super();
this.empNo = empNo;
this.name = name;
}
public String getEmpNo() {
return empNo;
}
public void setEmpNo(String empNo) {
this.empNo = empNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public abstract String getStatus();
}
public class FullTimeEmployee extends Employee {
public FullTimeEmployee(String empNo, String name) {
super(empNo, name);
}
@Override
public String getStatus() {
return "Full-Time";
}
}
public class PartTimeEmployee extends Employee {
public PartTimeEmployee(String empNo, String name) {
super(empNo, name);
}
@Override
public String getStatus() {
return "Part-Time";
}
}
public class Test {
public static void main(String[] args) {
new Test().exec();
}
private void exec(){
Employee emp1 = new FullTimeEmployee("001", "张三");
Employee emp2 = new PartTimeEmployee("002", "李四");
System.out.println(emp1.getStatus());
System.out.println(emp2.getStatus());
}
}
public abstract class Employee {
private String empNo;
private String name;
public Employee(String empNo, String name) {
super();
this.empNo = empNo;
this.name = name;
}
public String getEmpNo() {
return empNo;
}
public void setEmpNo(String empNo) {
this.empNo = empNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public abstract String getStatus();
}
public class FullTimeEmployee extends Employee {
public FullTimeEmployee(String empNo, String name) {
super(empNo, name);
}
@Override
public String getStatus() {
return "Full-Time";
}
}
public class PartTimeEmployee extends Employee {
public PartTimeEmployee(String empNo, String name) {
super(empNo, name);
}
@Override
public String getStatus() {
return "Part-Time";
}
}
public class Test {
public static void main(String[] args) {
new Test().exec();
}
private void exec(){
Employee emp1 = new FullTimeEmployee("001", "张三");
Employee emp2 = new PartTimeEmployee("002", "李四");
System.out.println(emp1.getStatus());
System.out.println(emp2.getStatus());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询