用JAVA编写student类

2024年11月27日 23:50
有1个网友回答
网友(1):

public class Person {
private String name;
private int age;

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

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 class Student extends Person {
private String school;

public void getInfo() {
super.getInfo();
System.out.println("School: " + school);
}

public static void main(String[] args) {
Student s = new Student();
s.setName("aaa");
s.setAge(28);
s.setSchool("bbb");
s.getInfo();
}

public String getSchool() {
return school;
}

public void setSchool(String school) {
this.school = school;
}

}
打字不易,如满意,望采纳。