package hello.io;
import java.util.ArrayList;
public class Psvm {
public staticvoidmain(String[] args){
Teacher teacher = new Teacher();
System.out.println(teacher.listStu);
Student student = new Student(1,"hh");
Student student2 = new Student(2,"dd");
System.out.println(teacher);
teacher.listStu = new ArrayList<>();
teacher.listStu.add(student);
teacher.listStu.add(student2);
System.out.println(teacher.listStu.get(1));}}
package hello.io;
import java.util.List;
public class Teacher {a
int id;
String name;
List<Student> listStu;
public intgetId(){return id;}
public Teacher(){
System.out.println("老師構造");}
public voidsetId(int id){
this.id = id;}
public String getName(){return name;}
public voidsetName(String name){
this.name = name;
System.out.println("老師set");}
public List<Student>getListStu(){return listStu;}
public voidsetListStu(List<Student> listStu){
this.listStu = listStu;}
@Override
public String toString(){return"Teacher{"+"id="+ id +", name='"+ name +'\''+", listStu="+ listStu +'}';}}
package hello.io;
public class Student {int StuId;
String name;
public intgetStuId(){return StuId;}
public voidsetStuId(int stuId){
StuId = stuId;}
public String getName(){return name;}
public voidsetName(String name){
this.name = name;
System.out.println("學生set");}
public Student(int stuId, String name){
StuId = stuId;
this.name = name;}
public Student(){
System.out.println("學生構造");}
@Override
public String toString(){return"Student{"+"StuId="+ StuId +", name='"+ name +'\''+'}';}}