private String stuname
private String stunumber
private String stuclass
public StudentVo(String stuname, String stunumber, String stuclass) {
this.stuname = stuname
this.stunumber = stunumber
this.stuclass = stuclass
}
@Override
public String toString() {
return "StudentVo{" +
"我是'" + stuclass + '\'' +
"班级学生,我叫='" + stuname + '\'' +
", 学号为:'" + stunumber + '\'' +
'}'
}
public String getStuname() {
return stuname
}
public void setStuname(String stuname) {
this.stuname = stuname
}
public String getStunumber() {
return stunumber
}
public void setStunumber(String stunumber) {
this.stunumber = stunumber
}
public String getStuclass() {
return stuclass
}
public void setStuclass(String stuclass) {
this.stuclass = stuclass
}
}
这个很简单呀,要自己试着去写。\r\npublic class Students {\r\n\tprivate String ID//学号\r\n private String classId //班级\r\n private String name//姓名\r\n\tprivate int age //年龄\r\n public Students(String ID,String classId,String name,int age){//构造函数\r\n this.ID=ID\r\n this.classId=classId\t\r\n this.name=name\r\n this.age= age \r\n }\r\n\tpublic String getiID() {//获得学号\r\n\t\treturn this.ID\t\r\n}\r\n\tpublic String getClassId() {//获得班级\r\n\t\treturn this.classId\r\n\t}\r\n\tpublic String getName() {//获得姓名\r\n\t\treturn this.name\r\n\t}\r\n\tpublic int getAge() {//获得年龄\r\n\t\treturn this.age\r\n\t}\r\n\t\r\n\tpublic void setAge(int age){//修改年龄\r\n\t\tthis.age=age\r\n\t}\t\r\n\tpublic static void main(String args[]){\r\n\t\tStudents st=new Students("111101","一班","张三","20")\r\n\t\tSystem.out.println(st.getAge())\r\n\t\tst.setAge(30)\r\n\t\tSystem.out.println(st.getAge())\r\n\t}\r\n} \r\n如果在完整一些,可以在加一个toString()函数,用来返回要输出的字符串。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)