如何检查一些类是否实现接口? 当具有:如何检查一个对象是否实现了一个接口?
Character.Gorgon gor = new Character.Gorgon();
如何检查gor
实现Monster
接口?
public interface Monster {
public int getLevel();
public int level = 1;
}
public class Character {
public static class Gorgon extends Character implements Monster {
public int level;
@Override
public int getLevel() { return level; }
public Gorgon() {
type = "Gorgon";
}
}
}
是方法getLevel()
在Gorgon
覆盖正确的,所以它可以返回的新gor
level
产生的?
我认为你需要instanceof的关键字。 – 2012-04-15 20:43:57