interface CanFight
{
  void fight();
}interface CanSwin
{
  void swin();
}interface CanFly()
{
  void fly();
}class ActionCharacter
{
  public void fight(){}
}class Hero extends ActionCharacter
    implements CanFight, CanSwim, CanFly
{
  public void swim(){} 
  public woid fly(){}
}如果一个类实现这个接口,不是应该把接口里的方法都要重写吗,为什么这里没重写
接口CanFight的fight()方法呢??? (上面是thinking in java 3th里的代码)

解决方案 »

  1.   

    ActionCharacter这个类已经重写拉呀class ActionCharacter
    {
      public void fight(){}
    }
      

  2.   


    Hero 继承了ActionCharacter类ActionCharacter类重写了fight()
    class ActionCharacter
    {
      public void fight(){}
    }
      

  3.   

    楼上2位说的对呀,在JDK源代码中好多都这样实现的.
    顺便更正以下,"如果一个类实现这个接口,不是应该把接口里的方法都要重写吗",这句话,应该把这个重写(OVERRIDE)改成实现(implements )吧,这种说法不准确.