java吧 关注:1,239,932贴子:12,714,033
  • 2回复贴,共1

Java初学者 求人帮做一道题

只看楼主收藏回复

电器类Electic, 包括Open方法;分别建3个派生类 Light, Computer, Fan,重构Open方法; 新建一个测试类Demo,构造3种对象,调用Open方法


IP属地:浙江1楼2014-09-10 11:33回复
    class Electic{
    public void open(){
    System.out.println("打开电器");
    }
    }
    class Light extends Electic{
    public void open(){
    System.out.println("打开电灯");
    }
    }
    class Computer extends Electic{
    public void open(){
    System.out.println("打开电脑");
    }
    }
    class Fan extends Electic{
    public void open(){
    System.out.println("打开电扇");
    }
    }
    public class Demo {
    public static void main(String[] args){
    Light a1=new Light();
    Computer a2=new Computer();
    Fan a3=new Fan();
    a1.open();
    a2.open();
    a3.open();
    }
    }


    IP属地:贵州2楼2014-09-10 12:19
    收起回复