如何定义一个标准的类(POJO类)
POJO: Plain Old Java Object
- 所有成员变量都需要使用private关键字私有化
- 为每一个成员变量编写一对setter,getter方法
- 编写一个无参数的构造方法
- 编写一个全参数的构造方法
public class student {
//成员变量
private String name;
private int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public Student(String name,int age) {
this.age
}
public Student() {
}
public Student(String name,int age) {
//super();
this.name = name;
this.age = age;
}
}
特例 boolean的get方法
private boolean male;
public boolean isMale() {
return male;
}
标签:定义,如何,int,age,private,标准,String,public,name
From: https://www.cnblogs.com/kdlyh/p/17863214.html