用java定义一个学生类,要处理的信息有学号、姓名、年龄、专业。

2024-11-27 14:03:19
推荐回答(2个)
回答1:

// 一个简单的学生类
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 + "]";
}

}

回答2:

public class Student{

private int stu_no;
private String name;
private int age;
private String profession;

设置下get/set方法
话说你连定义个类都不会 要来有啥用呢

}