阅读背景:

控制反转IOC和依赖注入DI的区别

来源:互联网 

准备两个实体类:Student类 和 Teacher类

//1.Student实体类 
public class Student {
    private int sid;
    private String sname;
    private int age;
    //创建教师属性
    private Teacher teacher;

    public Student() {
    }

    public Student(int sid, String sname, int age) {
        this.sid = sid;
        this.sname = sname;
        this.age = age;
    }

    public Student(int sid, String sname) {
        this.sid = sid;
        this.sname = sname;
    }

    public Student(int sid, int age) {
        this.sid = sid;
        this.age = age;
    }

   (所有属性的getter和setter器)
   (重写toString方法)
   (重写equals和hashCode方法)
}


//2.Teacher实体类
public class Teacher {
    private int tid;
    private String tname;

    public Teacher() {
    }

    public Teacher(int tid, String tname) {
        this.tid = tid;
        this.tname = tname;
    }

    public Teacher(String tname) {
        this.tname = tname;
    }
    
   (所有属性的getter和setter器)
   (重写toString方法)
   (重写equals和hashCode方法)    
}//1



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: