/*
轉接器設計
*/
package pkg6.pkg41;
//轉接設計
interface Window{
public void fun1();
public void fun2();
public void fun3();
public void fun4();
public void fun5();
}
//定義一個抽象類別實現介面的所有方法
//但是,本體為空的
abstract class WindowAdapter implements Window{
public void fun1(){};
public void fun2(){};
public void fun3(){};
public void fun4(){};
public void fun5(){};
}
class WindowImp1 extends WindowAdapter{
public void fun1(){
System.out.println("執行fun1");
}
}
class WindowImp2 extends WindowAdapter{
public void fun2(){
System.out.println("執行fun2");
}
}
public class Main {
public static void main(String[] args) {
Window win = new WindowImp1(); //向上轉型
win.fun1();
win.fun2();
System.out.println("");
Window win2 = new WindowImp2(); //向上轉型
win2.fun1();
win2.fun2();
}
}
執行結果:
執行fun1
執行fun2
留言列表