接口的简单调用

接口的简单调用

1、问题描述:

图片描述

2、实现思路:

  1. 简单调用接口和继承父类即可实现。

  2. 功能做成接口

  3. 手机为父类,手机类型为子类。

3、实现代码:

package test;

public interface TheakePictures {
    public void takePictare();
}

package test;

public interface Network {
    public void networkConn();
}

package test;

public interface PlayWiring {
    public void play(String inContent);
}

package test;

public class Handset {
    private String brand;
    private String type;
    public void sendInfo(){
        System.out.println("发消息");
    }
    public void call(){
        System.out.println("通话");
    }
    public void info(){
        System.out.println("beand: "+brand+" type: "+type);
    }
    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 Handset(String brand, String type) {
        this.brand = brand;
        this.type = type;
    }
    
}

package test;

public class testDemo {
    public static void main(String[] args){
        AptitudeHandst aptitudeHandst=new AptitudeHandst("华为");
        CommonHandset commonHandset=new CommonHandset("苹果");
        System.out.println("-----------------------------------------------------");
        System.out.println("智能手机:");
        aptitudeHandst.info();
        aptitudeHandst.takePictare();
        aptitudeHandst.networkConn();
        aptitudeHandst.play("鸿蒙2.0.MP4");
        aptitudeHandst.sendInfo();
        aptitudeHandst.call();
        System.out.println("-----------------------------------------------------");
        System.out.println("普通手机:");
        commonHandset.info();
        commonHandset.call();
        commonHandset.sendInfo();
        commonHandset.play("Can we kiss forever.mp3");
    }
}

package test;

public class AptitudeHandst extends Handset implements TheakePictures,Network,PlayWiring{

    
   

    public AptitudeHandst(String brand) {
        super(brand, "智能手机");
    }

    @Override
    public void networkConn() {
        // TODO Auto-generated method stub
        System.out.println(super.getBrand()+"正在连接网络");
    }

    @Override
    public void takePictare() {
        // TODO Auto-generated method stub
        System.out.println(super.getBrand()+"正在照相");
    }

    @Override
    public void play(String inContent) {
        // TODO Auto-generated method stub
        System.out.println(super.getBrand()+"正在播放视频: "+inContent);
    }
    
}

package test;

public class CommonHandset extends Handset implements PlayWiring{

    
    public CommonHandset(String brand) {
        super(brand, "普通手机");
    }

    @Override
    public void play(String inContent) {
        // TODO Auto-generated method stub
        System.out.println(super.getBrand()+"正在播放音频: "+inContent);
    }
    
}

4、运行结果:

图片描述

5、遇到的问题及解决方法:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值