用java定义一个学生类,要处理的信息有学号、姓名、年龄、专业。
2个回答
展开全部
// 一个简单的学生类
public class Student {
private int sno; // 学号
private String sname; // 姓名
private int sage; // 年龄
private String profession; // 专业
public Student() {
}
public Student(int sno, String sname, int sage, String profession) {
super();
this.sno = sno;
this.sname = sname;
this.sage = sage;
this.profession = profession;
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public int getSage() {
return sage;
}
public void setSage(int sage) {
this.sage = sage;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
@Override
public String toString() {
return "Student [sno=" + sno + ", sname=" + sname + ", sage=" + sage
+ ", profession=" + profession + "]";
}
}
public class Student {
private int sno; // 学号
private String sname; // 姓名
private int sage; // 年龄
private String profession; // 专业
public Student() {
}
public Student(int sno, String sname, int sage, String profession) {
super();
this.sno = sno;
this.sname = sname;
this.sage = sage;
this.profession = profession;
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public int getSage() {
return sage;
}
public void setSage(int sage) {
this.sage = sage;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
@Override
public String toString() {
return "Student [sno=" + sno + ", sname=" + sname + ", sage=" + sage
+ ", profession=" + profession + "]";
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询