数据存储之栈堆

 

栈存储的数据有:方法中的参数,随着方法的执行完而消失

堆存储的数据有: 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在该文中。

posted on 2015-09-22 16:35  &木子  阅读(651)  评论(0编辑  收藏  举报

导航