interface Friendly {    void sayHello();
    void sayGoodbye();
}
class Dog {    // How many times this dog wags its tail when
    // saying hello.
    private int wagCount = ((int) (Math.random() * 5.0)) + 1;    void sayHello() {        System.out.print("Wag");
        for (int i = 0; i < wagCount; ++i) {
            System.out.print(", wag");
        }
        System.out.println(".");
    }    public String toString() {        return "Woof!";
    }
}class CockerSpaniel extends Dog implements Friendly {    // How many times this Cocker Spaniel woofs when saying hello.
    private int woofCount = ((int) (Math.random() * 4.0)) + 1;    // How many times this Cocker Spaniel wimpers when saying
    // goodbye.
    private int wimperCount = ((int) (Math.random() * 3.0)) + 1;    public void sayHello() {        // Wag that tail a few times.
        super.sayHello();        System.out.print("Woof");
        for (int i = 0; i < woofCount; ++i) {
            System.out.print(", woof");
        }
        System.out.println("!");
    }    public void sayGoodbye() {        System.out.print("Wimper");
        for (int i = 0; i < wimperCount; ++i) {
            System.out.print(", wimper");
        }
        System.out.println(".");
    }
}
class Cat implements Friendly {
    public void eat() {        System.out.println("Chomp, chomp, chomp.");
    }    public void sayHello() {        System.out.println("Rub, rub, rub.");
    }    public void sayGoodbye() {        System.out.println("Scamper.");
    }    protected void finalize() {        System.out.println("Meow!");
    }
}

解决方案 »

  1.   

    都是在继承。
    extends是继承类是用,implements是继承接口时用。
    一个类只能用一次extends,而可以用多次implements。。
      

  2.   

    extends Dog implements Friendly 
    继承于类Dog 同时实现Friendly 接口
      

  3.   

    extends Dog implements Friendly 
    extends是继承Dog类,implements是实现了Friendly接口 
    super.sayHello(); 是调用了父类Dog的方法sayHello 
    LZ没有学过java的面向对象吗?如果没有就看看java的书是怎么讲的吧 
      

  4.   

    extends是继承父类,表示可以使用父类所有方法非私有的方法;
    implements是实现接口,表示必须要将说实现的接口中全部的抽象方法都要给出具体实现
      

  5.   

    继承+接口 看thinking in java 3rd 中文版 用心看