zoukankan      html  css  js  c++  java
  • 初学杂文 数据表映射

    class Teacher{
        private String name;
        private Student student [];  //多个学生用对象数组

        public Teacher(String name) {
            this.name = name ;
        }
        public void setStudent(Student [] student){  //设置学生时候
            this.student = student;
        }
        public String getInfo(){
            return "Name :" + name ;
        }
        public Student [] getStudent(){  //返回的是一个数组
            return this.student ;
        }
    }
    class Student{
        private String name;
        private int ID;
        private Teacher teacher ;

        public Student (String name,int ID){
            this.name = name;
            this.ID = ID;
        }
        public void setTeacher (Teacher teacher){
            this.teacher = teacher ;
        }
        public String getInfo(){
            return "Name :" + this.name +", ID:" + this.ID ;
        }
        public Teacher getTeacher (){
            return this.teacher ;
        }

    }
    public class Test{
        public static void main(String args[]){
            Student stu1 = new Student("zhang", 001);
            Student stu2 = new Student("zhuo", 002);
            Student stu3 = new Student("peng", 003) ;
            Teacher tea1 = new Teacher("Java") ;

            stu1.setTeacher(tea1) ;
            stu2.setTeacher(tea1) ;
            stu3.setTeacher(tea1) ;
            
            tea1.setStudent(new Student [] {stu1,stu2,stu3}) ; //设置老师的学生,传入的是数组

            System.out.println(stu1.getInfo());
            System.out.println(stu1.getTeacher().getInfo()) ;

            for(int i = 0; i < tea1.getStudent().length;i++ )  //获取数组的长度
                System.out.println(tea1.getStudent()[i].getInfo());

        }
    }

  • 相关阅读:
    如何使用php实现首页和子页面之间的交互
    用php实现,打开哪个页面哪个页面就有默认的样式
    后台链接前台有关显示不显示
    上传文件的最大值,post传值的最大值得修改
    linux 操作系统的安装,本地登录及远程登录,vnc连接操作详细步骤
    滑动组件
    Numpy简介
    java对象序列化
    集合类操作需要注意的地方
    TreeMap详解
  • 原文地址:https://www.cnblogs.com/da-peng/p/5060408.html
Copyright © 2011-2022 走看看