package com.excer;
public class Animal {
public String name; public void eat(){ System.out.println("吃东西"); } public static void main(String[] args){ Animal a = new Dog(); a.name = "毛毛"; System.out.println(a.name); a.eat(); a = new Cat(); a.name = "十元"; System.out.println(a.name); a.eat(); }}/**狗类*/class Dog extends Animal{ public String age; @Override public void eat(){ System.out.println("吃骨头"); }}/**猫类*/
class Cat extends Animal{ public String color; @Override public void eat(){ System.out.println("吃鱼"); }}