Java Head First & 多态

Java Head First  多态 - darrell - DARRELL的博客
 
Java Head First  多态 - darrell - DARRELL的博客
package com.cwcec.tag;

class Fruit
{    
}

class Apple extends Fruit{}

class Animal
{
    public Fruit eat(Fruit fruit)
    {
        System.out.println("Animal eat...");
        return fruit;
    }
    
}

class Dog extends Animal
{

    public Fruit eat(Apple apple) {
        System.out.println("Dog eat...");
        return apple;
    }
    
}

public class Single
{

    public static void main(String[] args) {
        
        Fruit fruit = new Fruit();
        Apple apple = new Apple();
        Animal animal = new Dog();
        animal.eat(apple);    
    }
}

 

posted @ 2018-01-18 13:48  darrell007  阅读(130)  评论(0编辑  收藏  举报