如何实现多个接口Implementing Multiple Interface

4.实现多个接口Implementing Multiple Interface 

接口的优势:马克-to-win:类可以实现多个接口。与之相反,类只能继承一个超类(抽象类或其他类)。 A class can implement multiple interface, but a class can have only one superclass. this is also the difference between abstract class and interface.

例1.4:---

interface HandPhone {
    void talk();
}
interface Computer {
    void surfWeb();
}
class SmartPhoneMark_to_win implements HandPhone, Computer {
    public void surfWeb() {
        System.out.println("只要有wifi, 我就能上网");
    }
    public void talk() {
        System.out.println("马克-to-win: 和传统电话一样, 我能通话");
    }
}
public class Test {
    public static void main(String args[]) {
        SmartPhoneMark_to_win sp = new SmartPhoneMark_to_win();
        sp.surfWeb();
        sp.talk();
    }
}

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/103110955

posted @ 2021-01-29 20:49  师徒行者  阅读(202)  评论(0编辑  收藏  举报