package cn.sxt.opp;
/*接口和实现*/
/*新建了2个接口,测试3个不同的类,在TestInterface 类中使用方法和常量,测试接口中能否调用类*/
public class TestInterface {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Volant v = new Angel();/* Angel里有1个方法和一个常量,但是Volant里只有1个方法,只能调用flay方法,不能调用helpOther常量, */
v.fly();
Honest h = new GoodMan();
h.helpOther();
}
}
/* 飞行接口 */
interface Volant {
int FLY_HETGH = 1000;
void fly();
}
/* 善良接口 */
interface Honest {
void helpOther();
}
/* 多继承 */
class Angel implements Volant, Honest {
@Override
public void helpOther() {
// TODO 自动生成的方法存根
System.out.println("Angel.helpOther");
}
@Override
public void fly() {
// TODO 自动生成的方法存根
System.out.println("Angel.fly()");
}
}
class GoodMan implements Honest {
@Override
public void helpOther() {
// TODO 自动生成的方法存根
System.out.println("GoodMan.helpOther()");
}
}
class Birdman implements Volant {
@Override
public void fly() {
// TODO 自动生成的方法存根
System.out.println("Birdman.fly()");
}
}