1. 首页
  2. 课程学习
  3. Java
  4. Java学生类代码示例

Java学生类代码示例

上传者: 2023-07-07 21:35:43上传 JAVA文件 503B 热度 14次

以下是一个Java学生类的代码示例:

public class Student {

    private String name;
    private int age;
    private String grade;

    public Student(String name, int age, String grade) {
        this.name = name;
        this.age = age;
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public String getGrade() {
        return grade;
    }

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

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

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

    public void displayInfo() {
        System.out.println("Name: " + name);
        System.out.println("Age: " + age);
        System.out.println("Grade: " + grade);
    }

    public static void main(String[] args) {
        Student student = new Student("John", 18, "12th");
        student.displayInfo();
    }
}
用户评论