public class TestDog {
public static void main(String[] args) {
Dog d = new Dog();
d.setAge(10);
d.setName("旺财");
d.setHostName("华安");
System.out.println("name:" + d.getName()
+ " 年龄:" + d.getAge() + " 主人:"
+ d.getHostName());
}
}
class Creator {
private int age;
public Creator() {
super();
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
class Animal extends Creator {
private String name;
public Animal() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class Dog extends Animal {
private String hostName;
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public Dog() {
super();
}
}
子类对象实例化的全过程
最新推荐文章于 2024-04-22 21:24:53 发布