这个部分有个细节,当父类没有这个方法的时候,需要强行转换
java类1
package com.bjsxt.testInterface;
/**
* 这是一个飞行器的接口
*/
public interface Volant {
/**
* 表示飞行器在地球这个星球上飞的最高的高度,单位是:公里
*/
/*public static final */int MAX_HIGHt = 100; //前面的部分可写可不写
/**飞行方法,飞行器可以起飞。
*
*/
/*public abstract */void fly();
/**
* 可以让飞行器停止,如果在空中就悬停,如果在地上就是静止。
*/
void stop();
}
/**善良接口*/
interface Honest{ //定义一个接口叫Honest
void helpOther();
}
java类2
package com.bjsxt.testInterface;
import org.w3c.dom.ls.LSOutput;
public class SuperMan implements Volant,Honest{
@Override
public void fly(){
System.out.println("横着飞!");
}
@Override
public void stop(){
System.out.println("竖着停");
}
@Override
public void helpOther(){
System.out.println("哪里call我,飞哪里!");
}
public static void main(String[] args) {
SuperMan m1 = new SuperMan();
m1.fly();
m1.helpOther();
Volant h1 = new SuperMan();
h1.fly();
Honest h = (Honest)h1;
h.helpOther();
}
}