class Person{
private String name;
private int age;
public Person(){
System.out.println("调用成功了");
}
public Person(String name){//Person的重载
this();
this.name=name;
}
public Person(String name,int age){
this(name);
this.age=age;
}
public void setName(String name){this.name=name;}
public void setAge(int age){this.age=age;}
public String getName(){return this.name;}
public int getAge(){return this.age;}
}
class Day7{
public static void main(String[] args) {
Person p=new Person();
System.out.println(p.getName()+"\n"+p.getAge());
}
} |
|