• 20150122--接口


    package com.hanqi.computer;
    
    public interface ICpu {
        
        public void yunSuan();
        
        public String getPinpai();
        
        
    }
    ICpu
    package com.hanqi.computer;
    
    public class AMDCpu implements ICpu,IDisplay {
    
        @Override
        public void yunSuan() {
            
            System.out.println("我的运算速度也不错");
            
        }
    
        @Override
        public String getPinpai() {
            
            return "AMD";
        }
    
        @Override
        public void xianShi() {
            
            System.out.println("APU");
            
        }
    
    }
    AMDCpu
    package com.hanqi.computer;
    
    public class Computer {
        
        private ICpu cpu;
        private IDisplay display;
        
        
        public ICpu getCpu() {
            return cpu;
        }
        public void setCpu(ICpu cpu) {
            this.cpu = cpu;
        }
        public IDisplay getDisplay() {
            return display;
        }
        public void setDisplay(IDisplay display) {
            this.display = display;
        }
    
        
        public void run()
        {
            System.out.println("Cpu品牌 = " + cpu.getPinpai());
            System.out.println(" 显卡品牌 = " + display.getPinpai());
            
            cpu.yunSuan();
            
            display.xianShi();
        }
        
        
    }
    Computer
    package com.hanqi.computer;
    
    public interface IDisplay {
        
        public void xianShi();    //    public 可不写 默认
        
        public String getPinpai();
        
        
        
    }
    IDisplay
    package com.hanqi.computer;
    
    public class IntelCpu implements ICpu {
    
        @Override
        public void yunSuan() {
    
            System.out.println("我的运算速度很快");
            
        }
    
        @Override
        public String getPinpai() {
            
            return "Intel";
        }
    
    }
    IntelCpu
    package com.hanqi.computer;
    
    public class Ti960Display implements IDisplay {
    
        @Override
        public void xianShi() {
            
            System.out.println("显示图形");
    
        }
    
        @Override
        public String getPinpai() {
            
            return "英伟达";
        }
    
    }
    Ti960Display
    package com.hanqi.computer;
    
    public class ZuZhuang {
    
        public static void main(String[] args) {
            
            //组装一台电脑
            Computer c1 = new Computer();
            
            ICpu intel = new IntelCpu();
            
            c1.setCpu(intel);                    //有名对象
            c1.setDisplay(new Ti960Display());    //匿名对象
            
            c1.run();
    
            Computer c2 = new Computer();
            
    //        AMDCpu a = new AMDCpu();
            
            LongXin a = new LongXin2();
            
            c2.setCpu(a);
            c2.setDisplay(a);
            
            c2.run();
        }
    
    }
    ZuZhuang
    package com.hanqi.computer;
    
    public interface ICpuDisplay extends ICpu, IDisplay {
        
    }
    ICpuDisplay
    package com.hanqi.computer;
    
    public abstract class LongXin implements ICpuDisplay {
    
        @Override
        public void yunSuan() {
            
            System.out.println("可以运算了");
    
        }
    
        @Override
        public String getPinpai() {
            
            return "龙芯";
        }
    
        @Override
        public abstract void xianShi();            //定义一个抽象方法
    }
    LongXin
    package com.hanqi.computer;
    
    public class LongXin2 extends LongXin {
    
        @Override
        public void xianShi() {
            System.out.println("可以显示");
    
        }
    
    }
    LongXin2

  • 相关阅读:
    net.sf.jsqlparser.statement.select.PlainSelect.getGroupByColumnReferences()Ljava/util/List(版本问题)
    Netty ByteBuf
    Vertx session 使用须知
    用Vert.x shiro jdbcRealm对restful api鉴权
    Vert.x发送 HTTP/HTTPS请求及重定向
    解决“hao123”劫持浏览器主页
    cannot find module bcrypt_lib.node
    nodejs运行项目报错TypeError: db.collection is not a function
    [Java] Stream flatMap
    [Spring Security] Authotization
  • 原文地址:https://www.cnblogs.com/name-hanlin/p/5152442.html
Copyright © 2020-2023  润新知