java定义一个标准类
一个标准类(Java Bean)的四个组成部分:
- 所有的成员变量都要使用private关键字修饰
- 编写一个无参数的构造方法
- 编写一个全参数的构造方法
- 为每一个成员变量编写一个Getter/Setter方法
public class Student{
private String name;
private int age;
private boolean isMale;
public Student(){
}
public Student( String name, int age, boolean isMale ){
this.name = name;
this.age = age;
this.isMale = isMale;
}
public String getName(){
return name;
}
public void setName( String name ){
this.name = name;
}
public int getAge(){
return age;
}
public void setAge( int age ){
this.age = age;
}
public boolean isMale(){
return isMale;
}
public void set isMale( boolean isMale ){
this.isMale = isMale;
}
}