标签:color ar java sp bs new as 方法 class
package com.test;
//方法重写(overwrite)
public class test3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//建立一只猫
Cat cat = new Cat();
//建立一只狗
Dog dog = new Dog();
//猫与狗的叫声
cat.cry();
dog.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("我是狗,我的叫声是汪汪!!");
}
}
标签:color ar java sp bs new as 方法 class
原文地址:http://www.cnblogs.com/milantgh/p/4036133.html