zoukankan      html  css  js  c++  java
  • 对象数组

    ⦁ 对象数组概述

    A:基本类型的数组:存储的元素为基本类型
    int[] arr={1,2,3,4}
    B:对象数组:存储的元素为引用类型
    Student[] stus=new Student[3];

    Student代表一个自定义类
    Stus数组中stus[0],stus[1],stus[2]的元素数据类型为Student,
    都可以指向一个Student对象
    ⦁ 对象数组案例:
    创建一个学生数组,存储三个学生对象并遍历

    举例:

    //创建学生数组
    Student[] students = new Student[3];

    //创建学生对象
    Student s1 = new Student("曹操",40);
    Student s2 = new Student("刘备",35);
    Student s3 = new Student("孙权",30);

    //把学生对象作为元素赋值给学生数组
    students[0] = s1;
    students[1] = s2;
    students[2] = s3;

    //遍历学生数组
    for(int x=0; x<students.length; x++) {
    Student s = students[x];
    //System.out.println(s);
    System.out.println(s.getName()+"---"+s.getAge());
    }

  • 相关阅读:
    C#设计模式总结
    【23】备忘录模式(Memento Pattern)
    【22】访问者模式(Visitor Pattern)
    mycat 分库
    mysql的存储过程
    mysql的视图
    mysql的索引
    mysql权限操作
    mysql事务操作
    mysql常用函数
  • 原文地址:https://www.cnblogs.com/yifengs/p/10707306.html
Copyright © 2011-2022 走看看