内存分为四块:heap(堆)、stack(栈)、data section 、code section
所有new出来的对象,都存在heap里。
局部变量保存在stack中,如果是引用型数据,值指向heap的对象。
所有静态数据储存在data section。
所有代码存在code section,所有对象共用方法代码。
String s = new String("hello");
分析这条语句:
1、创建s,存储在stack区,值为null
2、创建String对象,值为null,s的值指向String对象
3、创建hello,存储在data section区,把String对象的值修改成hello