如何实现多个接口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.
马克- to-win:马克 java社区:防盗版实名手机尾号: 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, 我就能上网");
}
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();
}
}
输出结果:
只要有wifi, 我就能上网
马克-to-win: 和传统电话一样, 我能通话