java 封装student编写
时间: 2023-05-26 17:05:46 浏览: 86
JAVA学生类Student
public class Student {
private String name;
private int age;
private String major;
public Student(String name, int age, String major) {
this.name = name;
this.age = age;
this.major = major;
}
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 String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public void study() {
System.out.println("I am studying " + major + ".");
}
}
阅读全文