有的话,请提供实例,谢谢

解决方案 »

  1.   

    package t2;public class Button {
    /*
     * private Light light = new Light();
     * 
     * public void pressOn()
     *  { light.turnOn(); }
     * 
     * public void pressOff() { light.turnOff(); }
     */
    public class Button
    {
            private Switch switch;         public Button(Switch switch)         {
                   this.switch = switch;
    }
    public void pressOn()
    {
           this.switch.trunOn();
    }
    public void pressOff()
    {
           this.switch.turnOff();
    }
    }
    }
      

  2.   

    Switch是一个接口,编译不通过
      

  3.   

    csdn首页的方法2:“凿壁借光”的模式场景实例运行错误
      

  4.   

    不管 Switch 是一个接口还是一个实例类,在Button的构造函数中,传入的那个Switch,肯定是一个实例类。
      

  5.   

    可以,示例发到你csdn邮箱
    你看看先