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

  2.   

    extends 是继承的关键字,Java中 继承是单继承的一个类只能继承一个父类,而实现是用关键字implements来区别的,一半是实现接口,实现可以有多实现,即实现多个接口,super()是调用父类属性方法的关键字;
    所以 extends Dog implements Friendly 
         extends是继承Dog类,implements是实现了Friendly接口 
         super.sayHello(); 是调用了父类Dog的方法sayHello