无关紧要
This commit is contained in:
@@ -1,2 +1,36 @@
|
||||
package chapter4.example14;public class Example14 {
|
||||
package chapter4.example14;
|
||||
|
||||
abstract class Animal {
|
||||
abstract void shout();
|
||||
}
|
||||
|
||||
class Cat extends Animal {
|
||||
public void shout() {
|
||||
System.out.println("喵喵...");
|
||||
}
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
public void shout() {
|
||||
System.out.println("汪汪...");
|
||||
}
|
||||
}
|
||||
|
||||
class Example14 {
|
||||
public static void main(String[] args) {
|
||||
Animal cat = new Cat();
|
||||
Animal dog = new Dog();
|
||||
|
||||
cat.shout();
|
||||
dog.shout();
|
||||
}
|
||||
}
|
||||
|
||||
class Example15 {
|
||||
public static void main(String[] args) {
|
||||
Dog dog = new Dog();
|
||||
Animal an = dog;
|
||||
|
||||
an.shout();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user