面向对象练习题

某家庭有电视机、洗衣机、电冰箱和微波炉。编程序显示家用电器的工作状态:电视机在播放节目、洗衣机在洗衣服、电冰箱在制冷以及微波炉在加热食物。

public class Practice5 {
    public static void main(String[] args) {
        class Work {
            String name;

            public Work() {
            }

            public Work(String name) {
                this.name = name;
            }

            public void work() {
                System.out.println("正在工作状态");
            }
        }




        class TV extends Work {        //电视类
            public TV(String name) {
                super(name);
            }
            public void work() {
                System.out.println(name + "正在播放节目");
            }
        }


        //洗衣服
        class Wash extends Work {
                 public Wash(String name) {
                     super(name);
                     
                 }
             public void work() {
                System.out.println(name + "正在洗衣服");
            }
        }

         //电冰箱
        class Ice extends  Work{
            public Ice(String name) {
              super(name);
            }
            public  void  work(){
                System.out.println(name+"正在制冷");
            }
        }

        //微波炉
        class Microwave extends  Work{
            public Microwave(String name) {
                super(name);
            }
            public  void work(){
                System.out.println(name+"正在加热食物");
            }
        }

           Work w;
           w =new TV("电视");
           w.work();
           w =new Wash("洗衣机");
           w.work();
           w =new Ice("电冰箱");
           w.work();
           w =new Microwave("微波炉");
           w.work();
        }
    }

你可能感兴趣的:(java,服务器,开发语言)