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

    /**
     把5个学生的信息存储到数组中,并遍历数组,获取得到每一个学生信息。
     3 *         学生:Student
     4 *         成员变量:name,age
     5 *         构造方法:无参,带参
     6 *         成员方法:getXxx()/setXxx()
     7 * 分析:
     8 *         A:创建学生类。
     9 *         B:创建学生数组(对象数组)。
    10 *         C:创建5个学生对象,并赋值。
    11 *         D:把C步骤的元素,放到数组中。
    12 *         E:遍历学生数组。
    13 *  */
    14 
    15 public class Practice 
    16 {
    17     public static void main(String[] args)
    18     {
    19         // 创建学生数组(对象数组)。
    20         Student[] students = new Student[5];
    21         // for (int x = 0; x < students.length; x++) 
    22         // {
    23         //         System.out.println(students[x]);
    24         // }
    25         //     System.out.println("---------------------");
    26 
    27         // 创建5个学生对象,并赋值。
    28         Student s1 = new Student("小明", 27);
    29         Student s2 = new Student("小红", 30);
    30         Student s3 = new Student("小强", 30);
    31         Student s4 = new Student("旺财", 12);
    32         Student s5 = new Student("张三", 35);
    33 
    34         // 将对象放到数组中。
    35         students[0] = s1;
    36         students[1] = s2;
    37         students[2] = s3;
    38         students[3] = s4;
    39         students[4] = s5;
    40 
    41         // 遍历
    42         for (int x = 0; x < students.length; x++) 
    43         {
    44             //System.out.println(students[x]);
    45             Student s = students[x];
    46             System.out.println(s.getName()+"---"+s.getAge());
    47         }
    48     }
    49 }

    对象数组的内存图解

  • 相关阅读:
    日期和时间运算:上月最后一天
    SY全局系统字段
    内表、结构赋值转换规则
    基本类型赋值转换规则表
    嵌套结构使用:struc1-struc2-XXX
    TYPES、DATA、TYPE、LIKE、CONSTANTS、STATICS、TABLES
    ABAP WRITE、WRITE TO、FORMAT语句
    ABAP DESCRIBE语句
    数据词典与ABAP类型映射
    Field+offset(len)
  • 原文地址:https://www.cnblogs.com/dhm520/p/8339887.html
Copyright © 2011-2022 走看看