Girish
Girish

Reputation: 21

Memory allocation in java

class Someobject
{
  int i=10;
}

public class OtherObject
{
  public static void main(String args[])
  {
    Someobject obj=new Someobject();
    System.out.println(obj.i);
  }
}

Please tell me in which section of the memory:

  1. This entire code will load.
  2. Where will someobject will be stored.
  3. Where will obj will be stored
  4. Where will i be stored.

Thanks every one in advance.

Upvotes: 2

Views: 204

Answers (1)

Kannan Ekanath
Kannan Ekanath

Reputation: 17631

  1. The code/classes will load in PermGenSpace
  2. The Objects are created in the HEAP
  3. The obj reference is stored on the stack
  4. i is part of the SomeObject instance which lives in the HEAP.

Upvotes: 4

Related Questions