日期:2014-05-18 浏览次数:20751 次
public class Demo{
public static void main(String args[]){
Dog dog = new Dog("小狗");
System.out.println(dog.getName());
Animal a = new Animal("动物");
System.out.println(a.getName());
dog.setName("我是小狗");
System.out.println(dog.getName());
a.setName("我是动物");
System.out.println(a.getName());
}
}
class Animal{
private String name;
Animal(){
}
Animal(String name){
this.name = name;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
}
class Dog extends Animal{
Dog(){
}
Dog(String name){
super(name);
}
}
}