zoukankan      html  css  js  c++  java
  • 接口实现手机

    手机的功能接口类:

    /**
     * @author Administrator
     *连接网络功能接口
     */
    public interface Network {
        public abstract void networkConn();
    }
    
    
    /**
     * @author Administrator
     *    音频播放功能接口
     */
    public interface PlayWiring {
        public abstract void play(String name);
    }
    
    
    /**
     * @author Administrator
     *    拍照功能接口
     */
    public interface ThreakePicture {
        public abstract void takePicture();
    }

    智能手机以及普通手机共有的属性以及方法构成的父类:

    public abstract class Handset {
        private String band;
        private String type;
        
        
        public String getBand() {
            return band;
        }
        public void setBand(String band) {
            this.band = band;
        }
        public String getType() {
            return type;
        }
        public void setType(String type) {
            this.type = type;
        }
        
        
        public void sendInfo() {
            System.out.println("发短信的功能");
        }
        
        public void call() {
            System.out.println("打电话的功能");
        }
        
        public abstract void info();
        
    }

    智能手机类:

    public class AptitudeHandset extends Handset implements ThreakePicture,Network,PlayWiring{
        
        public void info() {
            System.out.println("我是一台"+this.getBand()+" "+this.getType()+"手机");
        }
    
        @Override
        public void play(String name) {
            System.out.println("正在播放"+name);
            
        }
    
        @Override
        public void networkConn() {
            
            System.out.println("我有连接网络的功能");
        }
    
        @Override
        public void takePicture() {
            System.out.println("我有拍照功能");
            
        }
    
        
    }

    普通手机类:

    public class CommonHandset extends Handset implements PlayWiring {
    
        public void play(String name) {
            System.out.println("正在播放"+name);
    
        }
    
        @Override
        public void info() {
            System.out.println("我是一台"+this.getBand()+" "+this.getType()+"手机");
    
        }
    }

    测试类:

    public class Text {
        public static void main(String[] args) {
            AptitudeHandset ad = new AptitudeHandset();
            ad.setBand("苹果");
            ad.setType("6plus");
            ad.info();
            ad.call();
            ad.sendInfo();
            ad.networkConn();
            ad.takePicture();
            ad.play("最炫民族风");
            System.out.println();
            
            CommonHandset ch = new CommonHandset();
            ch.setBand("诺基亚");
            ch.setType("15");
            ch.info();
            ch.call();
            ch.sendInfo();
            ch.play("最炫民族风");
    
        }
    }

    测试运行结果:

  • 相关阅读:
    openwrt 相关文章
    负载均衡相关文章
    Today's Progress
    Rodrigues formula is beautiful, but uneven to sine and cosine. (zz Berkeley's Page)
    Camera Calibration in detail
    Fundamental Matrix in Epipolar
    Camera Calibration's fx and fy do Cares in SLAM
    FilterEngine::apply
    FilterEngine 类解析——OpenCV图像滤波核心引擎(zz)
    gaussBlur
  • 原文地址:https://www.cnblogs.com/Dean-0/p/11208620.html
Copyright © 2011-2022 走看看