当前位置:网站首页>创建对象时JVM内存结构

创建对象时JVM内存结构

2022-06-27 19:21:00 zhengmayusi

代码
  1. Student类:
public class Student {
    
    int no;
    String name;
    int age;
    boolean sex;
    String address;
}
  1. StudentTest类:
public class StudentTest {
    
    public static void main(String[] args) {
    
        Student s1 = new Student();
        Student s2 = new Student();
    }
}
JVM中对应内存结构图

在这里插入图片描述
note:

  1. s1、s2是局部变量(在方法中创建的变量),局部变量存储在栈内存中
  2. 对象和引用的区别?
  • 对象是通过new出来的,在堆内存中存储
  • 引用是:但凡是变量,并且该变量中保存了内存地址,指向了堆内存当中的对象(此例中main方法中的变量s1、s2就是保存了对象Student在堆内存中的地址)
原网站

版权声明
本文为[zhengmayusi]所创,转载请带上原文链接,感谢
https://blog.csdn.net/ailaohuyou211/article/details/125456892