//Critter类
package critter;
/**
* @author admin
*
*/
public class Critter
{
private String name;
/**
* @param name
* the name to set
*/
public void setName(String name)
{
this.name = name;
}
public void getinfo()
{
System.out.println(this.name);
}
}
//Dog类
package dog;
import critter.Critter;
/**
* @author admin
*
*/
public class Dog extends Critter
{
private int old;
/**
* @param old
* the old to set
*/
public void setOld(int old)
{
this.old = old;
}
//重载getinfo方法
public void getinfo(String name)
{
System.out.println("animalName:" + name);
System.out.println("animalage:" + this.old);
}
}
//测试类
import critter.Critter;
import dog.Dog;
/**
* @author admin
*
*/
public class Test
{
public static void main(String[] arg)
{
Critter c = new Critter();
c.setName("Dog");
c.getinfo();
Dog d = new Dog();
d.setName("Dog2");
d.setOld(2);
d.getinfo();
d.getinfo("Dog2");
}
}
给你写好了
这个也需要高手写么?