test9.1

来源:互联网 发布:mysql minute函数 编辑:程序博客网 时间:2024/06/09 05:39

把Rodent 编程一个抽象类,内部的方法也变成抽象方法

abstract class Rodent{
public abstract void apperence();
}
class Mouse extends Rodent{
public void apperence(){System.out.println("It runs fast");}
}
class Hamster extends Rodent{
public void apperence(){System.out.println("It's so big");}
}
class Gerbil extends Rodent{
public void apperence(){System.out.println("It's eyes are small");}
}
public class Test1 {
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().

0 0