定义一个外部类Person,类中包含姓名、性别、年龄等属性以及对这些属性的相应操作;然后在Person类中定义一个静态成员内部类Student,Studen中包含学号和成绩。另外在编写一个测试类,在测试类中能够对输出学生信息:3120190901234 王明 男 22 89 说明:根据题。自行确定内部类Student中的属性和方法。
时间: 2024-02-29 09:54:39 浏览: 74
类和对象的定义-java类和对象
好的,根据您的要求,我来为您展示一个符合要求的Java代码:
```java
public class Person {
private String name;
private String gender;
private int age;
public Person(String name, String gender, int age) {
this.name = name;
this.gender = gender;
this.age = age;
}
public String getName() {
return name;
}
public String getGender() {
return gender;
}
public int getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public void setGender(String gender) {
this.gender = gender;
}
public void setAge(int age) {
this.age = age;
}
public static class Student {
private String studentId;
private int score;
public Student(String studentId, int score) {
this.studentId = studentId;
this.score = score;
}
public String getStudentId() {
return studentId;
}
public int getScore() {
return score;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public void setScore(int score) {
this.score = score;
}
}
}
```
在测试类中,可以这样调用:
```java
public class Test {
public static void main(String[] args) {
Person.Student student = new Person.Student("3120190901234", 89);
Person person = new Person("王明", "男", 22);
System.out.println(student.getStudentId() + " " + person.getName() + " " + person.getGender() + " " + person.getAge() + " " + student.getScore());
}
}
```
输出结果为:
```
3120190901234 王明 男 22 89
```
希望这个代码能够帮助到您!
阅读全文