public class Student {
創(chuàng)新互聯(lián)主營思南網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,成都app開發(fā),思南h5重慶小程序開發(fā)公司搭建,思南網(wǎng)站營銷推廣歡迎思南等地區(qū)企業(yè)咨詢
private String sno; //學號
private String name; //姓名
private String sex; //性別
private String calss; //班級
private String major; //專業(yè)
public String getSno() {
return sno;
}
public void setSno(String sno) {
this.sno = sno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getCalss() {
return calss;
}
public void setCalss(String calss) {
this.calss = calss;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public Student() {
}
public Student(String sno, String name) {
this.sno = sno;
this.name = name;
}
public Student(String sno, String name, String sex, String calss,
String major) {
this.sno = sno;
this.name = name;
this.sex = sex;
this.calss = calss;
this.major = major;
}
這個比較簡單,我說一下方法,你打開eclipse,新建一個項目,然后在src里面新建一個學生類,后面的一步一步走,那步不懂就問
這個很簡單呀,要自己試著去寫。
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){//構造函數(shù)
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()函數(shù),用來返回要輸出的字符串。