XXX门的实现过程: 流程:
设计一张抽象的门Door,那么对于这张门来说,就应该拥有所有门的共性,开门openDoor()和关门closeDoor();然后对门进行另外的功能设计,防盗--theftproof()、防水--waterproof()、防弹--bulletproof()、防火、防锈…… 要求:利用继承、抽象类、接口的知识设计该门
bulletproof.java
package MXDX24;
//防弹门类
public class bulletproof extends Door implements gongneng {
@Override
//防弹门类重写开门方法
void openDoor() {
System.out.println("防弹门已打开");
}
@Override
//防弹门类重写开门方法
void closeDoor() {
// TODO Auto-generated method stub
System.out.println("防弹门已关闭");
}
public void fangdao(){
System.out.println("");
}
public void fangshui(){
System.out.println("");
}
//防弹门类实现接口功能
public void fangdan(){
System.out.println("我具有防弹的工能哦");
}
}
Door.java
package MXDX24;
public abstract class Door {
//抽象方法开门
abstract void openDoor();
//抽象方法关门
abstract void closeDoor();
}
//创建功能接口
interface gongneng {
//防盗功能
void fangdao();
//防水功能
void fangshui();
//防弹功能
void fangdan();
}
test.java
package MXDX24;
public class test {
public static void main(String[] args) {
theftproof tf=new theftproof();
tf.closeDoor();
tf.openDoor();
tf.fangdao();
waterproof wf=new waterproof();
wf.closeDoor();
wf.openDoor();
wf.fangshui();
bulletproof bf=new bulletproof();
bf.closeDoor();
bf.openDoor();
bf.fangdan();
}
}
theftproof.java
package MXDX24;
//防盗门类
public class theftproof extends Door implements gongneng {
@Override
//防盗门类重写开门方法
void openDoor() {
System.out.println("防盗门已打开");
}
@Override
//防盗门类重写关门方法
void closeDoor() {
// TODO Auto-generated method stub
System.out.println("防盗门已关闭");
}
//防盗门类实现功能接口
public void fangdao(){
System.out.println("我具有防盗的工能哦");
}
public void fangshui(){
System.out.println("");
}
public void fangdan(){
System.out.println("");
}
}
waterproof.java
package MXDX24;
//防水门类
public class waterproof extends Door implements gongneng {
@Override
//防水门类重写开门方法
void openDoor() {
System.out.println("防水门已打开");
}
@Override
//防水门类重写开门方法
void closeDoor() {
// TODO Auto-generated method stub
System.out.println("防水门已关闭");
}
public void fangdao(){
System.out.println("");
}
//防水门类实现功能接口
public void fangshui(){
System.out.println("我具有防水的工能哦");
}
public void fangdan(){
System.out.println("");
}
}