接口的简单调用
1、问题描述:
2、实现思路:
-
简单调用接口和继承父类即可实现。
-
功能做成接口
-
手机为父类,手机类型为子类。
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);
}
}