package sdfsfsd;
interface Software {
public void run();
}
class AppStore implements Software {
@Override
public void run() {
System.out.println("run app store");
}
}
class Camera implements Software {
@Override
public void run() {
System.out.println("run camera");
}
}
abstract class Phone {
protected Software software;
public void setSoftware(Software software) {
this.software = software;
}
public abstract void run();
}
class Oppo extends Phone {
@Override
public void run() {
software.run();
}
}
class Vivo extends Phone {
@Override
public void run() {
software.run();
}
}
public class qiaojie {
public static void main(String[] args) {
Phone p1;
p1=new Oppo();
p1.setSoftware(new AppStore()); p1.run();
p1=new Vivo();
p1.setSoftware(new Camera());p1.run();
}
}
结果:
run app store
run camera