请教几个JAVA的问题 高手进

2024-12-22 01:47:56
推荐回答(1个)
回答1:

IPerson:

public interface IPerson {
void print();
}

Teacher:

public class Teacher implements IPerson {
private String num;

private String name;

private int workAge;

private String job;

public Teacher(String num, String name, int workAge, String job) {
this.num = num;
this.name = name;
this.workAge = workAge;
this.job = job;
}

public Teacher(String num, int workAge) {
this.num = num;
this.workAge = workAge;
}

public void print() {
System.out.println(this.name + "的工号是 :\t" + this.num + "\t年龄是 :\t" + this.workAge);
}
}

Director:

public class Director implements IPerson {
private String num;

private String name;

private int workAge;

private String job;

private String assistantName;

public Director(String num, String name, int workAge, String job,
String assistantName) {
this.num = num;
this.name = name;
this.workAge = workAge;
this.job = job;
this.assistantName = assistantName;
}

public void print() {
System.out.println(this.name + "的工号是 :\t" + this.num + "\t助手是 :\t" + this.assistantName);
}
}

Start: 用于测试,运行这个就可以看到效果

public class Start {

public static void main(String[] args) {
IPerson personT = new Teacher("TEACHER:001", "刘德华", 3, "数学老师");
IPerson personD = new Director("DIRECTOR:001", "周杰伦", 3, "教导主任", "蔡依琳");
personT.print();
personD.print();
}

}