package com.test;
//多态性
public class test4 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Animal an = new Cat();
an.cry();
an = new Dog();
an.cry();
}
}
class Animal
{
// private String name;
//
// private String color;
//
// private float weight;
//
public void cry()
{
System.out.println("我是动物,我不知道怎么叫!!");
}
}
class Cat extends Animal
{
public void cry()
{
System.out.println("我是猫,我的叫声是喵喵!!");
}
}
class Dog extends Animal
{
public void cry()
{
System.out.println("我是狗,我的叫声是汪汪!!");
}
}