test8.9

class Rodent{
public void apperence(){System.out.println("It has four feet");}
}
class Mouse extends Rodent{
@Override public void apperence(){System.out.println("It runs fast");}
}
class Hamster extends Rodent{
@Override public void apperence(){System.out.println("It's so big");}
}
class Gerbil extends Rodent{
@Override public void apperence(){System.out.println("It's eyes are small");}
}
public class Test9 {
public static void main(String[] args) {
Rodent[] r={new Mouse(),new Gerbil(),new Hamster()};
for(Rodent i:r)
i.apperence();
}
}
//the output shows r[0,1,2] operate its own apperence().

你可能感兴趣的:(Java)