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();
Door door = new Door() {
@Override
public void open() {
System.out.println("临时实现的关门方法");
}
@Override
public void close() {
System.out.println("临时实现关门的方法");
}
};
}
}
public abstract class Door {
/* public void open(){
System.out.println("门的作用之一是开门");
}
public void close(){
System.out.println("门的作用之二是关门");
}*/
public abstract void open();
public abstract void close();
}
package edu.xcdq.demo01;
import edu.xcdq.demo01.Door;
public class KeypadDoor extends Door {
public void open(){
System.out.println("按键盘输入密码开门");
}
public void close(){
System.out.println("拉上即可自动锁门");
}
}
package edu.xcdq.demo01;
import edu.xcdq.demo01.Door;
public class PowerDoor extends Door {
public void open(){
System.out.println("按遥控器开门");
}
public void close(){
System.out.println("按遥控器关门");
}
}