問題如下1在base包中?
在javastudy包中,定義一個類Test1,前面的比較簡單 有問題再聯系package javastudy;import base.Animal;import base.Mammal;import base.Reptile;import utility.Cat;import utility.Crocodile;import utility.Dog;import utility.Monkey;import utility.Person;import utility.Snake;public class Test1 {Animal animal[] = { new Cat(), new Crocodile(), new Dog(), new Monkey(), new Person(), new Snake() };public static void main(String[] args) {new Test1();}public Test1() {//構造方法for (int i = 0; i <= 5; i++) {if (animal[i] instanceof Animal)((Animal) animal[i]).eat();((Animal) animal[i]).sleep();((Animal) animal[i]).show();if (animal[i] instanceof Mammal) {((Mammal) animal[i]).milk();System.out.println();} else if (animal[i] instanceof Reptile) {((Reptile) animal[i]).crawl();System.out.println();}}}}