//类适配器public class Client {
public static void main(String[] args) {
// TODO Auto-generated method stub
Phone phone = new Phone();
phone.charging(new VoltageAdapter());
}
}
public class Phone {
public void charging(IVoltage5V iVoltage5V) {
if(iVoltage5V.output5V() ==5) {
System.out.println("V5~~");
} elseif (iVoltage5V.output5V() >5) {
System.out.println("220~~");
}
}
}
public interface IVoltage5V {
public int output5V();
}
public class Voltage220V {
//220V
public int output220V() {
int src =220;
System.out.println("Voltage220V="+ src);
return src;
}
}
public class VoltageAdapter extends Voltage220V implements IVoltage5V {
@Override
public int output5V() {
// TODO Auto-generated method stub
int srcV = output220V();
int dstV = srcV /44 ;
return dstV;
}
}