Java中的内存解析
- new的对象都放到堆中,如对象,数组 new Test();
- 方法中的变量都是局部变量,局部变量放到栈中 int c;
- 类实体中的变量放到堆中 (全局变量) int num;
- 引用类型的变量,只能存储两类值:null 或 地址值 test
class Test{
int num;
public int add(int a,int b){
int c;
c = a + b;
return c;
}
}
在main方法中
Test test = new Test();