如何實現(xiàn)多個接口Implementing Multiple Interface
4.實現(xiàn)多個接口Implementing Multiple Interface
接口的優(yōu)勢:馬克-to-win:類可以實現(xiàn)多個接口。與之相反,類只能繼承一個超類(抽象類或其他類)。 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ū):防盜版實名手機尾號: 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)電話一樣, 我能通話