接口练习案例:防盗门
package com.guoba.jiekoudemo;
public interface fangdao extends gongneng{
void fangdao();
}
package com.guoba.jiekoudemo;
//包含防盗功能和防水功能
public interface gongneng {
void fangcheng();
void fangshui();
}
package com.guoba.jiekoudemo;
public class Test implements fangdao{
private int fangchenzhishu = 5;
private int fangshuishendu = 30;
public int getFangchenzhishu() {
return fangchenzhishu;
}
public void setFangchenzhishu(int fangchenzhishu) {
this.fangchenzhishu = fangchenzhishu;
}
public int getFangshuishendu() {
return fangshuishendu;
}
public void setFangshuishendu(int fangshuishendu) {
this.fangshuishendu = fangshuishendu;
}
@Override
public void fangcheng() {
System.out.println("防尘已开启,防尘质数:"+getFangchenzhishu());
}
@Override
public void fangshui() {
System.out.println("防水已开启,防水深度:"+getFangshuishendu());
}
@Override
public void fangdao() {
System.out.println("防盗已开启");
}
public static void main(String[] args) {
Test test = new Test();
test.fangdao();
test.fangcheng();
test.fangshui();
}
}
- 运行效果图