这个很简单呀,要自己试着去写。
public class Students {
private String ID; //学号
private String classId; //班级
private String name; //姓名
private int age; //年龄
public Students(String ID,String classId,String name,int age){//构造函数
this.ID=ID;
this.classId=classId;
this.name=name;
this.age= age;
}
public String getiID() {//获得学号
return this.ID;
}
public String getClassId() {//获得班级
return this.classId;
}
public String getName() {//获得姓名
return this.name;
}
public int getAge() {//获得年龄
return this.age;
}
public void setAge(int age){//修改年龄
this.age=age;
}
public static void main(String args[]){
Students st=new Students("111101","一班","张三","20");
System.out.println(st.getAge());
st.setAge(30);
System.out.println(st.getAge());
}
}
如果在完整一些,可以在加一个toString()函数,用来返回要输出的字符串。
public class Students {
public String id;
public String name;
public int age;
public String classId;
public String getId() {
return id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getClassId() {
return classId;
}
public void modifyAge(int age){
this.age=age;
}
public static void main(String args[]){
Students st=new Students();
System.out.println(st.getAge());
st.modifyAge(30);
System.out.println(st.getAge());
}
}
class Student{
String name ...
...
void getNo() {..;}
void getClass() {..;}
void getName() {..;}
void getAge() {..;}
private age setAge() {..;}
}