Java程序语言设计 根据要求编写程序

2024-11-17 23:33:34
推荐回答(1个)
回答(1):

//人接口
public interface Human {
void speak();
}

//教师类

public class Teacher implements Human {

public void speak() {

System.out.println("speak");

}

public void teach() {

System.out.println("teach");

}

}

//学生类

public class Student implements Human {

public void speak() {

System.out.println("speak");

}

public void learn() {

System.out.println("learn");

}

}

//测试类

class HumanTest {

@Test

void test() {

Teacher teacher=new Teacher();

Student stu=new Student();

teacher.teach();

teacher.speak();

stu.learn();

stu.speak();

}

}

运行结果:

teach

speak

learn

speak