接口实现手机

手机的功能接口类:

/**
 * @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("最炫民族风");

    }
}

测试运行结果:

 

posted on 2019-07-18 17:15  迪恩9  阅读(505)  评论(0编辑  收藏  举报