interface Function{
void takePicture();
void viewing();
}
abstract class Feature{
private String name;
private double price;
public Feature(){ }
public Feature(String name,double price){
this.name=name;
this.price=price;
}
public String getName(){
return name;
}
public double getPrice(){
return price;
}
abstract public String getInfo();
}
class Smartphone extends Feature implements Function{
private String OS;
public Smartphone(String name,double price,String os){
super(name,price);
this.OS=os;
}
public void takePicture(){
System.out.println(this.getName()+"手机拍照!");
}
public void viewing(){
System.out.println(this.getPrice()+"手机看照片!");
}
public String getInfo(){
return"名称:"+getName()+",价格"+getPrice()+",智能手机操作系统:"+this.OS;
}
public void passmessage(String message){
System.out.println(this.getName()+"智能手机发送了短信:"+message);
}
}
class Camera extends Feature implements Function{
private double zoom;
public Camera(String name,double price,double zoom){
super(name,price);
this.zoom=zoom;
}
public void takePicture(){
System.out.println(this.getName()+"数码照相机照相!");
}
public void viewing(){
System.out.println(this.getName()+"数码照相机浏览照片!");
}
public String getInfo(){
return "名称:"+this.getName()+",价格:"+this.getPrice()+",数码相机的变焦倍数:"+this.zoom;
}
public void printPhoto(){
System.out.println(this.getName()+"数码相机打印照片!");
}
}
class Demo0204{
public static void main(String[] args) {
Smartphone hw=new Smartphone("华为",5600,"鸿蒙");
Camera ca=new Camera("佳能",3500,20);
System.out.println("智能手机信息\n"+hw.getInfo());
System.out.println("数码照相机信息\n"+ca.getInfo());
hw.viewing();
hw.takePicture();
hw.passmessage("你好!");
ca.printPhoto();
ca.takePicture();
ca.viewing();
}
}
标签:String,price,接口,案例,void,应用,out,public,name
From: https://blog.csdn.net/2401_83192736/article/details/137481754