2 changed files with 36 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||||
|
package Animal; |
||||
|
|
||||
|
public abstract class Animal { |
||||
|
abstract void makeSound(); |
||||
|
} |
||||
|
interface Swimmable{ |
||||
|
void swim(); |
||||
|
} |
||||
|
class Dog extends Animal implements Swimmable{ |
||||
|
@Override |
||||
|
public void makeSound(){ |
||||
|
System.out.println("汪汪汪————"); |
||||
|
} |
||||
|
@Override |
||||
|
public void swim(){ |
||||
|
System.out.println("小狗正在游泳..."); |
||||
|
} |
||||
|
} |
||||
|
class Cat extends Animal{ |
||||
|
@Override |
||||
|
public void makeSound(){ |
||||
|
System.out.println("喵喵喵————"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
package Animal; |
||||
|
|
||||
|
public class AnimalTest { |
||||
|
public static void main(String[] args){ |
||||
|
Swimmable dog1=new Dog(); |
||||
|
Animal dog2=new Dog(); |
||||
|
Animal cat=new Cat(); |
||||
|
cat.makeSound(); |
||||
|
dog2.makeSound(); |
||||
|
dog1.swim(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue