日期:2014-05-20 浏览次数:20840 次
package ex14; public class TestAbstractClass { public static void main(String[] args) { // TODO 自动生成方法存根 Animal animal=new Chicken(); eat(animal); animal=new Duck(); eat(animal); } public static void eat(Animal animal){ animal.howToEat(); } } abstract class Animal{ public abstract void howToEat(); } class Chicken extends Animal{ public void howToEat(){ System.out.println("Fry it"); } } class Duck extends Animal{ public void howToEat(){ System.out.println("Roast it"); } }