zoukankan      html  css  js  c++  java
  • Memory map of an object array

    Student类:
    package com.itheima;
    /*
     * 自动生成构造方法:
     *         代码区域右键 -- Source -- Generate Constructors from Superclass...    无参构造方法
     *         代码区域右键 -- Source -- Generate Constructor using Fields...        带参构造方法
     * 自动生成getXxx()/setXxx():
     *         代码区域右键 -- Source -- Generate Getters and Setters...
     */
    public class Student {
        private String name;
        private int age;
        
        public Student() {
            
        }
    
        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getAge() {
            return age;
        }
    
        public void setAge(int age) {
            this.age = age;
        }
        
        
    }
    Student的测试类:
    package com.itheima;
    /*
     * 创建一个学生数组,存储三个学生对象并遍历
     * 
     * 分析:
     *         A:定义学生类
     *         B:创建学生数组
     *         C:创建学生对象
     *         D:把学生对象作为元素赋值给学生数组
     *         E:遍历学生数组
     */
    public class StudentDemo {
        public static void main(String[] args) {
            //创建学生数组
            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());
            }
        }
    }

    对应的内存图:

  • 相关阅读:
    JDK的几种分析工具
    心理价值
    通过Proxool辅助数据库优化
    人生缄言
    grep 用法
    多服务器快速定位
    RandomAccessFile读取远程系统日志
    20101116 视频处理几个常用指令
    Flickr架构
    JAVA正则表达式语法
  • 原文地址:https://www.cnblogs.com/lzp123456-/p/9795488.html
Copyright © 2011-2022 走看看