zoukankan      html  css  js  c++  java
  • Java数组与栈内存、堆内存

    package ch4;
    
    /**
     * Created by Jiqing on 2016/11/9.
     */
    public class ArrayInRam {
        public static void main(String[] args) {
            int[] a = {5,7,20};
            int[] b = new int[4];
            System.out.println("b数组的长度为:"+b.length);
            for(int i = 0,len = a.length;i<len;i++) {
                System.out.println(a[i]);
            }
    
            // 循环输出b数组的元素
            for (int i = 0,len = b.length;i<len;i++) {
                System.out.println(b[i]);
            }
    
            // b引用指向a引用的数组
            b = a;
            System.out.println("b数组的长度为:"+b.length);
            for (int i = 0,len = b.length;i<len;i++) {
                System.out.println(b[i]);
            }
    
            a[1] = 11;
            System.out.println(b[1]); // 值变了
    
        }
    }
    
    

    package ch4;
    
    /**
     * Created by Jiqing on 2016/11/9.
     */
    public class Person {
        public int age; // 年龄
        public double height; // 身高
        public void info() {
            System.out.println("我的年龄是:"+age+",我的身高是:"+height);
        }
    }
    
    
    package ch4;
    
    /**
     * Created by Jiqing on 2016/11/9.
     */
    public class Student {
        public static void main(String[] args) {
            Person[] students;
            students = new Person[2];
            Person zhang = new Person();
            zhang.age = 15;
            zhang.height = 158;
    
            Person lee = new Person();
            lee.age = 16;
            lee.height = 161;
    
            students[0] = zhang;
            students[1] = lee;
            lee.info(); // 我的年龄是:16,我的身高是:161.0
            students[1].info(); // 我的年龄是:16,我的身高是:161.0
        }
    }
    
    


  • 相关阅读:
    软件项目管理阅读笔记02
    大二下周总结(11)
    “帮你APP”团队冲刺9
    “帮你APP”团队冲刺8
    “帮你APP”团队冲刺7
    “帮你APP”团队冲刺6
    “帮你APP”团队冲刺5
    单词统计
    “帮你APP”团队冲刺4
    “帮你APP”团队冲刺3
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/6048370.html
Copyright © 2011-2022 走看看