如何實(shí)現(xiàn)多個(gè)接口Implementing Multiple Interface

4.實(shí)現(xiàn)多個(gè)接口Implementing Multiple Interface


接口的優(yōu)勢(shì):馬克-to-win:類可以實(shí)現(xiàn)多個(gè)接口。與之相反,類只能繼承一個(gè)超類(抽象類或其他類)。 A class can implement multiple interface, but a class can have only one superclass. this is also the difference between abstract class and interface.
馬克- to-win:馬克 java社區(qū):防盜版實(shí)名手機(jī)尾號(hào): 73203。
例1.4:---本章源碼

interface HandPhone {
    void talk();
}
interface Computer {
    void surfWeb();
}
class SmartPhoneMark_to_win implements HandPhone, Computer {
    public void surfWeb() {
        System.out.println("只要有wifi, 我就能上網(wǎng)");
    }
    public void talk() {
        System.out.println("馬克-to-win: 和傳統(tǒng)電話一樣, 我能通話");
    }
}
public class Test {
    public static void main(String args[]) {
        SmartPhoneMark_to_win sp = new SmartPhoneMark_to_win();
        sp.surfWeb();
        sp.talk();
    }
}

輸出結(jié)果:
只要有wifi, 我就能上網(wǎng)
馬克-to-win: 和傳統(tǒng)電話一樣, 我能通話