Java学生类代码示例
以下是一个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();
}
}
用户评论