栈存储的数据有:方法中的参数,随着方法的执行完而消失
堆存储的数据有: new出来的对象,由程序员分配内存
全局区:静态数据和常量
public Class MyTest { int math; int chinese; public MyTest(int math,int chinese) { this.math = math; this.chinese = chinese; } public int SaySomething() { int total =this.math + this.chinese; return total; } } public Class Test { static void main() { int math = 79;//栈 int chinese =80;//栈 static int aa = 40;//全局区 // myTest 栈 new MyTest(math,chinese)堆 MyTest myTest = new MyTest(math , chinese); int total = myTest.SaySomething();//栈 } }
详细介绍http://blog.sina.com.cn/s/blog_8e7c33e9010100e5.html在该文中。
时间: 2024-11-09 09:50:54