对于基本类型当中的boolean值,Getter方法一定要写成isXxx的形式,而setXxx规则不变
public class demo06Student {
private String name ; //姓名
private int age ; //年龄
private boolean male; //是不是男生
public void setMale(boolean b){
male = b;
}
public boolean isMale(){
return male;
}
public void setName(String str){
name = str;
}
public String getName(){
return name ;
}
public void setAge(int num){
age = num;
}
public int getAge(){
return age;
}
}
public class demo06 {
public static void main(String[] args) {
demo06Student stu = new demo06Student();
stu.setName("鹿晗");
stu.setAge(20);
stu.setMale(true);
System.out.println("姓名:" + stu.getName());
System.out.println("年龄:" + stu.getAge());
System.out.println("是不是男生:" + stu.isMale());
}
}