TestThis1.java
public class TestThis1{
/*定义成员变量*/
private String personName;//姓名
private int personAge;//年龄
private String personSex;//性别
person.setPersonVar("王义",25,"男");
System.out.println("姓名:"+person.personName+",年龄:"+person.personAge+",性别:"+person.personSex);
}
}
TestThis2.java
public class TestThis2{
/*定义成员变量*/
String personName;//姓名
int personAge;//年龄
String personSex;//性别
/*定义构造函数TestThis2()*/
public TestThis2(){
System.out.println("构造了一个新的对象!");
}
/*定义构造函数TestThis2(String name, int age, String sex)*/
public TestThis2(String name, int age, String sex){
this();
personName = name;
personAge = age;
personSex = sex;
}
public static void main(String args[]){
/*调用函数生成对象person */
TestThis2 person = new TestThis2("李玲",20,"女");
System.out.println("姓名:"+ person.personName+",年龄:"+ person.personAge+",性别:"+ person.personSex);
}
}