class Animal { 
public String name;
Animal(String name) {
this.name = name;
}
String getName(){
return name;
}
}class Dog extends Animal {
public String furcolour;
Dog(String name, String furcolour) {
super(name);
this.furcolour = furcolour;
}
String getFur() {
return furcolour;
}

}
class Cat extends Animal {
public String eyescolour;
Cat(String name, String eyescolour) {
super(name);
this.eyescolour = eyescolour;
}

String getEyes() {
return eyecolour;
}
}
public class TestFClass {
TestFClass test = new TestFClass();
Animal a = new Animal("name");
Cat c = new Cat("mimi","blue");
Dog d = new Dog("hotdog","yellow");
test.f(a);//需要标示符;
test.f(c);//需要标示符;
test.f(d);//需要标示符;
public void f(Animal a) {
System.out.pringln("name  "+a.getName);
if (a instanceof Cat) {
Cat x = (Cat)a;
System.out.println("eyescolour is "+x.getEyes());
 
}
else if(a instanceof Dod) {
Dog b = (Dog)a;
  System.out.println("furcolour is "+b.getFur());
}
}
}

解决方案 »

  1.   

    全是拼写错误!!!pringln
    a.getName() 
    Dod没有main方法!!!public static void main(String args[]){
    STest test = new STest();
        Animal a = new Animal("name");
        Cat c = new Cat("mimi","blue");
        Dog d = new Dog("hotdog","yellow");
        test.f(a);
        test.f(c);
        test.f(d);
    }
      

  2.   

    写了几个错别字,逻辑不能写在类里,要写在方法里package test;class Animal {
    public String name; Animal(String name) {
    this.name = name;
    } String getName() {
    return name;
    }
    }class Dog extends Animal {
    public String furcolour; Dog(String name, String furcolour) {
    super(name);
    this.furcolour = furcolour;
    } String getFur() {
    return furcolour;
    }}class Cat extends Animal {
    public String eyescolour; Cat(String name, String eyescolour) {
    super(name);
    this.eyescolour = eyescolour;
    } String getEyes() {
    return eyescolour;
    }
    }public class TestFClass { public void f(Animal a) {
    System.out.println("name  " + a.getName());
    if (a instanceof Cat) {
    Cat x = (Cat) a;
    System.out.println("eyescolour is " + x.getEyes()); } else if (a instanceof Dog) {
    Dog b = (Dog) a;
    System.out.println("furcolour is " + b.getFur());
    }
    } public static void main(String[] args) {
    TestFClass test = new TestFClass();
    Animal a = new Animal("name");
    Cat c = new Cat("mimi", "blue");
    Dog d = new Dog("hotdog", "yellow"); test.f(a);// 需要标示符;
    test.f(c);// 需要标示符;
    test.f(d);// 需要标示符;
    }
    }
      

  3.   

    这的跟记事本差不多,UltraEdit现在在自学
      

  4.   

    class Animal { 
        public String name;
        Animal(String name) {
            this.name = name;
        }
        String getName(){
            return name;
        }
    }class Dog extends Animal {
        public String furcolour;
        Dog(String name, String furcolour) {
            super(name);
            this.furcolour = furcolour;
        }
        String getFur() {
            return furcolour;
        }
        
    }
    class Cat extends Animal {
        public String eyescolour;
        Cat(String name, String eyescolour) {
            super(name);
            this.eyescolour = eyescolour;
        }
        
        String getEyes() {
            return eyescolour;
        }
    }
    public class TestFClass {
    public static void main(String[] args) {
        TestFClass test = new TestFClass();
        Animal a = new Animal("name");
        Cat c = new Cat("mimi","blue");
        Dog d = new Dog("hotdog","yellow");
        test.f(a);//需要标示符;
        test.f(c);//需要标示符;
        test.f(d);//需要标示符; }    
        public void f(Animal a) {
            System.out.println("name  "+a.getName());
            if (a instanceof Cat) {
                Cat x = (Cat)a;
                System.out.println("eyescolour is "+x.getEyes());             
                }
            else 
             if(a instanceof Dog) {
             Dog b = (Dog)a;
             System.out.println("furcolour is "+b.getFur());
            }
        }
    }