Java之接口

门类接口设计与实现
本文介绍了一种门类接口的设计方法,包括抽象基类Door及其实现子类AntiTheftDoor和FireDoor。通过定义防盗门(AntiTheftDoor)和消防门(FireDoor)接口,并结合具体实现类,展示了面向对象设计原则的应用。

运行结果如图所示,根据结果编写相应的接口、实现类以及测试类

public abstract class Door {
	
	/**
	 * 功能:开门
	 * author:wangpeng
	 * time:2018年8月2日下午2:32:11
	 */
	public abstract void open();
	/**
	 * 功能:关门
	 * author:wangpeng
	 * time:2018年8月2日下午2:32:23
	 */
	public abstract void close();
}
/**
 * 防盗门接口
 * 类名:AntiTheftDoor.java
 * 作者:wangpeng
 * 时间:2018年8月2日下午2:28:36
 */
public interface AntiTheftDoor {
	
	/**
	 * 功能:防盗
	 * author:wangpeng
	 * time:2018年8月2日下午2:30:34
	 */
	void burglarproof();
	/**
	 * 功能;门铃
	 * author:wangpeng
	 * time:2018年8月2日下午2:30:55
	 */
	void doorbell();
}
/**
 * 消防门接口
 * 类名:FireDoor.java
 * 作者:wangpeng
 * 时间:2018年8月2日下午2:28:06
 */
public interface FireDoor {
	/**
	 * 功能:防火
	 * author:wangpeng
	 * time:2018年8月2日下午2:31:50
	 */
	void fire_prevention();
}
public class AntiTheftDoorT extends Door implements AntiTheftDoor{

	@Override
	public void burglarproof() {
		// TODO Auto-generated method stub
		System.out.println("防盗门有防盗的功能");
	}

	@Override
	public void doorbell() {
		// TODO Auto-generated method stub
		System.out.println("防盗门有门铃的功能");
	}

	@Override
	public void open() {
		// TODO Auto-generated method stub
		System.out.println("防盗门有开的功能");
	}

	@Override
	public void close() {
		// TODO Auto-generated method stub
		System.out.println("防盗门有关的功能");
	}

}
public class FireDoorT extends Door implements FireDoor{

	@Override
	public void fire_prevention() {
		// TODO Auto-generated method stub
		System.out.println("消防门有防火的功能");
	}

	@Override
	public void open() {
		// TODO Auto-generated method stub
		System.out.println("消防门有开的功能");
	}

	@Override
	public void close() {
		// TODO Auto-generated method stub
		System.out.println("消防门有关的功能");
	}

}
public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		AntiTheftDoorT antiTheft=new AntiTheftDoorT();
		antiTheft.open();
		antiTheft.close();
		antiTheft.burglarproof();
		antiTheft.doorbell();
		
		FireDoorT fireDoor=new FireDoorT();
		fireDoor.open();
		fireDoor.close();
		fireDoor.fire_prevention();
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值