java-集合-realdo-集合一对多
2020-12-25 16:28
标签:override setname alt new img 大学 set oid com school类: student 类: test java-集合-realdo-集合一对多 标签:override setname alt new img 大学 set oid com 原文地址:https://www.cnblogs.com/java-quan/p/13038583.htmlpackage setdone;
import java.util.List;
public class School {
private String schoolname;
private List
package setdone;
public class Student {
private String name;
private String school;
private int age;
public Student(String name, int age) {
this.name = name;
this.school = school;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Student{" +
"name=‘" + name + ‘\‘‘ +
", school=‘" + school + ‘\‘‘ +
", age=" + age +
‘}‘;
}
}
package setdone;
import java.util.ArrayList;
import java.util.List;
public class SsTest {
public static void main(String[] args) {
Student student1 = new Student("张三",22);
Student student2 = new Student("李四",42);
Student student3 = new Student("王五",23);
School school = new School("清华大学");
student1.setSchool(school.getSchoolname());
student2.setSchool(school.getSchoolname());
student3.setSchool(school.getSchoolname());
List
上一篇:c++头文件循环引用
文章标题:java-集合-realdo-集合一对多
文章链接:http://soscw.com/index.php/essay/38172.html