//1.定义目标被适配类
//2.定义适配器接口,期望输出
//3.定义适配器类,继承被适配器类,实现适配器接口
//4.测试
/**
- 被适配类,输出的是220V
*/
public class Voltage220V {
public int outPut220V(){
return 220;
}
}
/**
- 提供适配接口
/
public interface IVoltage5V {
/*- 适配接口
- @return
*/
int output5V();
}
/**
- 1.继承被适配器类,实现适配器接口
*/
public class VoltageAdapter extends Voltage220V implements IVoltage5V{
public int output5V() {
int src = outPut220V();
return src/44;
}
}
public class AdapterTest {
public static void main(String[] args) {
VoltageAdapter adapter=new VoltageAdapter();
System.out.println(adapter.output5V());
}
}