1.创建老师类和学生类,两个类都实现了问候接口和工作接口,模拟上课的场景,运行效果如下:
package Zaria; interface hello{ public void speak(); } interface work{ public void dowork(); } class Student implements hello,work{ public void speak(){ System.out.println("peter:老师好"); } public void dowork(){ System.out.println("peter:同学开始记笔记"); } } class Teacher implements hello,work{ public void speak(){ System.out.println("mike:同学们好"); } public void dowork(){ System.out.println("mike:老师开始上课"); } } public class MoniShangKe{ public static void main(String[] args){ Student s=new Student(); Teacher t=new Teacher(); s.speak(); t.speak(); t.dowork(); s.dowork(); } }