/**
* 测试接口的基本语法
*/
public class TestInterface {
public static void main(String[] args) {
Volant v = new Angel();
v.fly();
// v.helpOther();
Honest h = new Angel();
h.helpOthers();
}
}
//飞行器接口
interface Volant {
int FLY_HIGHT = 100;//默认有前缀public static final
void fly();//默认有前缀public abstract
}
//善良接口
interface Honest {
void helpOthers();
}
class Angel implements Volant,Honest {
@Override
public void fly() {
System.out.println("我是天使,飞呀飞呀");
}
@Override
public void helpOthers() {
System.out.println("我是天使,喜欢扶老奶奶过马路");
}
}
/**
* 测试接口的多继承
*/
public class TestInterface2 implements C{
@Override
public void testA() {
System.out.println("TestInterface2.testA");
}
@Override
public void testB() {
System.out.println("TestInterface2.testB");
}
@Override
public void testC() {
System.out.println("TestInterface2.testC");
}
public static void main(String[] args) {
C c = new TestInterface2();
c.testC();
c.testA();
c.testB();
B b = new TestInterface2();
b.testB();
}
}
interface A {
void testA();
}
interface B {
void testB();
}
interface C extends A,B{
void testC();
}