Java Head First & 多态

Posted 学海无涯

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);    
    }
}

 

以上是关于Java Head First & 多态的主要内容,如果未能解决你的问题,请参考以下文章

Head first java chapter 7 继承与多态

java基础三 [深入多态,接口和多态](阅读Head First Java记录)

Head First Java & 继承

Head First Java & static

Head First Java & final

Head First Java & 构造函数