我在user.java中设定
public class User {
private String name;
private boolean male;
public boolean isMale() {
return male;
}
public void setMale(boolean male) {
this.male = male;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
在test.java中想访问,
User user=new User();
user.setName( "Tom ");
但是编译报错:User(java.lang.String,java.lang.String,boolean) in cn.ac.i
ct.User cannot be applied to ()
User user=new User();
^
于是我又把“User user=new User();”改成了“User u;”,
但还是报错“variable u might not have been initialized”。
怎么写u的初始化?
------解决方案--------------------