//人接口
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