public class BZL {
private String name;//姓名
private int age;//年龄 //成员变量
public BZL() { //无参数的构造方法
}
public BZL(String name, int age) { //有参数的构造方法
this.name = name;
this.age = age;
}
public String getName() { //Getter/Setter方法
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class UseBZL {
public static void main(String[] args) {
Student stu1 = new Student();
stu1.setName("迪丽热巴");
stu1.setAge(22);
System.out.println("姓名:" + stu1.getName() + ",年龄是:" + stu1.getAge());
System.out.println("=========");
Student stu2 = new Student("古力娜扎",22);//这里错误
System.out.println();
System.out.println("姓名:" + stu2.getName() + ",年龄是:" + stu2.getAge());
}
}