Java程序设计,定义一个表示学生的类Student

2024-11-27 12:21:26
推荐回答(5个)
回答1:

public class Student { //定义一个学生类
private int StuNum; //学号
private int Class; //班级
private char Gender; //性别
private int Age; //年龄
public Student(int StuNum, int Class, char Gender, int Age){//构造函数
this.stuNum = StuNum;
this.class = Class;
this.gender = Gender;
this.age = Age;
}
public int getStuNum() { //获得学号
return StuNum;
}

public int getClass() { //获得班级号
return Class;
}

public char getGender() { //获得性别
return Gender;
}
public void setGender(char Gender) { //修改性别
this.Gender = Gender;
}
public int getAge() { //获得年龄
return Age;
}
public void setAge(int Age) { //修改年龄
this.Age = Age;
}

public class Pupil extends Student //小学生
{
//...(由于没说派生后要新加什么东西,所以这里写了省略号,如果想在
// 新派生出来的类里加点什么特殊的东西,直接在省略号位置加就行了
// 下同)
}

public class MidSchoolStu extends Student //中学生
{
//...
}

public class UnderGraduate extends Student //大学生
{
//...
}

public class PostGraduate extends Student //研究生
{
//...
}

public class FreshStudent extends UnderGraduate //一年级学生
{
//...
}

public class Sophomore extends UnderGraduate //二年级学生
{
//...
}

public class Junior extends UnderGraduate //三年级学生
{
//...
}

public class Senior extends UnderGraduate //四年级学生
{
//...
}

public class Master extends PostGraduate //硕士生
{
//...
}

public class Doctor extends PostGraduate //博士生
{
//...
}

回答2:

这就是一个JAVABean,多看看基础知识,别什么都问别人,这样对你没好处!

回答3:

package bean;
public class Student {
private String sno;
private String name;
private String sex;
private int age;
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 int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

//下面测试方法
public static void main(String[] args)
{
Student student=new Student();
student.getAge();
student.getName();
student.getSex();
student.getSno();
}

}

回答4:

这简直不能再简单了吧。。。没有一点技术含量

回答5:

package afg;

public class Student {
public String sno;
public String name;
public String sex;
public int age;
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 int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

}