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());
}
}
}
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());
}
}
}
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);
}
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);// 需要标示符;
}
}
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());
}
}
}