1.创建Door
public class Door {
public void open(){
System.out.println("开门");
}
public void close() {
System.out.println("关门");
}
}
2.创建KeypadDoor
public class KeypadDoor extends Door{
public void open() {
System.out.println("输入密码开门");
}
public void close() {
System.out.println("轻轻关上,自动锁门");
}
}
3.创建PowerDoor
public class PowerDoor extends Door {
public void open() {
System.out.println("按遥控开门");
}
public void close() {
System.out.println("按遥控锁门");
}
}
4.运行
public class Demo01 {
public static void main(String[] args) {
KeypadDoor keypadDoor = new KeypadDoor();
keypadDoor.open();
keypadDoor.close();
PowerDoor powerDoor = new PowerDoor();
powerDoor.open();
powerDoor.close();
}
}