首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

关于接口和接口中多肽有关问题的实例

2012-09-10 
关于接口和接口中多肽问题的实例/** * 关于接口和接口中多肽问题的实例 ** @author iflytek **/interface

关于接口和接口中多肽问题的实例

/** * 关于接口和接口中多肽问题的实例 *  * @author iflytek *  */interface Singer {public void sing();public void sleep();}interface Painter {public void paint();public void eat();}class Student implements Singer {private String name;Student(String name) {this.name = name;}public void study() {System.out.println("studying......");}@Overridepublic void sing() {System.out.println("student sing......");}@Overridepublic void sleep() {System.out.println("student sleep......");}}class Teacher implements Singer, Painter {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}Teacher(String name) {this.name = name;}public void teach() {System.out.println("teacher teach......");}@Overridepublic void paint() {System.out.println("teacher paint......");}@Overridepublic void eat() {System.out.println("teacher eat......");}@Overridepublic void sing() {System.out.println("teacher sing......");}@Overridepublic void sleep() {System.out.println("teacher sleep......");}}public class TestSinger {public static void main(String[] args) {Singer s1 = new Student("le");s1.sing();Singer s2 = new Teacher("steven");s2.sing();s2.sleep();Painter p1 = (Painter) s2;p1.paint();p1.eat();System.out.println((Painter) s2 instanceof Teacher);System.out.println(s2 instanceof Teacher);System.out.println(p1 instanceof Teacher);}}

热点排行