今天跟大家分享一个接口的案例:
public class KGJ {
public void control(IflyTool f){
f.fly();
}
public static void main(String[] args) {
KGJ k = new KGJ();
k.control(new Superman());
}
}
interface IflyTool {
public void fly();}
class Superman implements IflyTool{
public void fly(){
System.out.println("用超能力飞");
}
}
class Bird implements IflyTool{
public void fly(){
System.out.println("用翅膀飞");
}
}
class Plane implements IflyTool{
public void fly(){
System.out.println("用发动机飞");
}
}