5 changed files with 44 additions and 0 deletions
@ -0,0 +1,5 @@ |
|||
package Sound; |
|||
|
|||
public abstract class Animal { |
|||
public abstract void makeSound(); |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
package Sound; |
|||
|
|||
public class Cat extends Animal{ |
|||
@Override |
|||
public void makeSound(){ |
|||
System.out.println("喵喵"); |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
package Sound; |
|||
|
|||
public class Dog extends Animal implements Swimmable{ |
|||
@Override |
|||
public void makeSound(){ |
|||
System.out.println("汪汪"); |
|||
} |
|||
@Override |
|||
public void swim(){ |
|||
System.out.println("小狗在游泳"); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
package Sound; |
|||
|
|||
public class Main{ |
|||
public static void main(String[] args){ |
|||
Animal dog = new Dog(); |
|||
Animal cat = new Cat(); |
|||
|
|||
dog.makeSound(); |
|||
cat.makeSound(); |
|||
|
|||
Dog myDog = new Dog(); |
|||
myDog.swim(); |
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
package Sound; |
|||
|
|||
public interface Swimmable { |
|||
public abstract void swim(); |
|||
} |
|||
Loading…
Reference in new issue