Java定义一个学生类Student,记录学生的姓名学号和可选课程数量

2024-11-27 09:48:55
推荐回答(1个)
回答1:

public class $ {

public static void main(String[] args) {

Student s0 = new Student();
System.out.println(s0);

Studentmen s1 = new Studentmen();
System.out.println(s1);
}
}

class Student {

private long id;
private String name;
private int age;
private double grade;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public double getGrade() {
return grade;
}

public void setGrade(double grade) {
this.grade = grade;
}

public String toString() {
return "我是学生";
}
}

class Studentmen extends Student {

private String duty;

public String getDuty() {
return duty;
}

public void setDuty(String duty) {
this.duty = duty;
}

public String toString() {
return "我是班干部";
}
}