题目:
代码:
public interface interfaceA {
public abstract String eat();
public abstract String live();
}
class Student implements interfaceA{
private String eatery;
private String dorm;
Student(String eatery, String dorm){
this.eatery = eatery;
this.dorm = dorm;
}
public String eat(){
return"食堂"+eatery;
}
public String live(){
return "宿舍"+dorm;
}
}
class Teacher implements interfaceA{
private String teachereatery;
private String schoolflat;
Teacher(String teachereater , String schoolflat){
this.teachereatery = teachereater;
this.schoolflat =schoolflat;
}
public String eat(){
return"教师食堂"+teachereatery;
}
public String live(){
return "学校公寓"+schoolflat;
}
}
class ParentsofStudents implements interfaceA{
private String resthouse;
ParentsofStudents(String resthouse){
this.resthouse = resthouse;
}
public String eat() {
return "招待所"+resthouse;
}
public String live(){
return "招待所"+resthouse;
}
}
public class Client{ //测试类
public static void main(String[] args) {
Student stu = new Student(null,null);
stu.eat();
stu.live();
Teacher tea = new Teacher(null,null);
tea.eat();
tea.live();
ParentsofStudents par = new ParentsofStudents(null);
par.eat();
par.live();
}
}