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());
}
}
根据代码判断,若你写了两个文件。需要注意两个文件的编译顺序。先编译Student类,再编译UserStudent类。
PS:希望你在提问的时候,可以简单描述下问题的现象,大家充分了解了你的问题后才能给出能够帮到的你答案。
你的类名不是 BZL 吗?
下面变成 Student 类了。
你上面用的是BZL类下面用的是Student类,把“public class BZL “里的所有“BLZ”改成“ Student“或者你把你写的Student类发出来看看