abstract class Animal { int legs; public Animal(int legs){ this.legs=legs; } public Animal(){} public abstract void eat(); public void walk(){ //System.out.println("动物用"+legs+"走路"); } public void play(){ } } class Spider extends Animal{ public Spider(int legs){ this.legs=legs; } public void eat(){ //System.out.println("动物eat!"; } } interface Pet{ public String getName(); public void setName(String name); } class Cat extends Animal implements Pet{ String name; public Cat(){} public Cat(String name){ this.name=name; } @Override public String getName(){ return this.name; } @Override public void setName(String name) { this.name=name; } public void eat(){ System.out.println(name+"喜欢Jerry!"); } public void play(){ System.out.println(name+"喜欢毛线球!"); } } class Fish extends Animal implements Pet{ String name; public Fish(){} public Fish(String name){ this.name=name; } @Override public void setName(String name){ this.name=name; } @Override public String getName(){ return this.name; } public void eat(){ System.out.println(name+"喜欢浮游生物!"); } @Override public void play(){ System.out.println(name+"喜欢水泡泡!"); } public void walk(){ System.out.println(name+"走路不用脚"); } } public class AnimalsTest{ public static void main(String[] args){ Cat Tom=new Cat("Tom"); Tom.eat(); Tom.play(); Tom.setName("Tom's son"); Tom.play(); Fish Nemo=new Fish("Nemo"); Nemo.eat(); Nemo.play(); Nemo.walk(); }