getter和setter方法的一些注意事项
布尔型应该用isxxx()进行设置,而get方法不变
class代码
public class Person {
private String name;
private boolean is_male;
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setIs_male(boolean isMale)
{
this.is_male=isMale;
}
public boolean isIs_male()
{
return is_male;
}
}
main代码
public class demo01 {
public static void main(String[] args) {
Person one = new Person();
one.setName("蔡徐坤");
one.setIs_male(true);
System.out.println("姓名:"+one.getName()+"----是不是男的:"+one.isIs_male());
}
}
标签:name,boolean,String,getter,注意事项,male,public,setter
From: https://www.cnblogs.com/harper886/p/17298896.html