zoukankan      html  css  js  c++  java
  • 手机

    手机类

    package cn.phone;
    
    public class Phone {
            private String brand;
            private String type;
            public void sendInfo() {
                System.out.println("发信息的功能");
            }
            public void call() {
                System.out.println("通电话的功能");
            }
            
            public String getBrand() {
                return brand;
            }
            public void setBrand(String brand) {
                this.brand = brand;
            }
            public String getType() {
                return type;
            }
            public void setType(String type) {
                this.type = type;
            }
            public  void print() {
                System.out.println("这是一部"+this.brand+this.getType()+"手机");
            }
    }

    接口类

    package cn.phone;
    //照相接口
    public interface TheakePictures {
        public void takePictures() ;
    }
    package cn.phone;
    //l连接网络接口
    public interface Network {
        public void networkConn();
    }
    package cn.phone;
    //播放接口
    public interface PlayWiring {
        public void play();
    }

    智能手机类

    package cn.phone;
    
    public class AptitudePhone extends Phone implements TheakePictures,Network,PlayWiring{
        public void takePictures() {
            System.out.println("照相功能");
        }
        public void networkConn() {
            System.out.println("连接网络功能");
        }
        public void play() {
            System.out.println("播放功能");
        }
    //    public void print() {
    //        
    //        System.out.println();
    //    }
        
        public void toprint() {
            super.call();
            super.sendInfo();
            takePictures();
            networkConn();
            play();
        }
    }

    普通手机类

    package cn.phone;
    
    public class CommonPhone extends Phone implements PlayWiring {
        public void play() {
            System.out.println("播放功能");
        }
        public void toprint() {
            super.call();
            super.sendInfo();
            play();
            
        }
    }

    测试类

    package cn.phone;
    
    public class Test {
        public static void main(String[] args) {
            Phone phone = new Phone();
            AptitudePhone aptitudePhone = new AptitudePhone();
            aptitudePhone.setBrand("苹果");
            aptitudePhone.setType("xr");
            aptitudePhone.print();
            aptitudePhone.toprint();
            CommonPhone commonPhone = new CommonPhone();
            commonPhone.setBrand("VIVO");
            commonPhone.setType("X9");
            commonPhone.print();
            commonPhone.toprint();
        }
    }

  • 相关阅读:
    【五】服务熔断、降级 —— Hystrix(豪猪)
    32. Springboot 系列(八)动态Banner与图片转字符图案的手动实现
    31.【微服务架构】SpringCloud之Feign(五)
    新SQL temp
    lombok踩坑与思考
    lombok注解介绍
    叉乘实现角色和敌人的位置判断(左上,左下,右上,右下)
    2维,3维向量单位化
    2个2D向量计算交点的夹角和补角
    Unity编辑器-创建单独编辑框,折叠框,提示框
  • 原文地址:https://www.cnblogs.com/lev1/p/11218815.html
Copyright © 2011-2022 走看看