Phone function interface classes:
/ **
* @author Administrator
* network connection function interface
* /
public interface the Network {
public abstract void networkConn ();
}
/ **
* @author Administrator
* audio play function interfaces
* /
public interface PlayWiring {
public abstract void Play (String name);
}
/ **
* @author Administrator
* camera interfaces
* /
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("最炫民族风");
}
}
测试运行结果: