2
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.

3
  • Please use the formatting to get this code more readable. Indent the code with four spaces so that is displays nicely. Commented Apr 17, 2010 at 18:39
  • To recieve a good answer it would help to put your question in an apropriate way. Please use code blocks for code, and it would also make things easier to read, if you make the numbered list more readable. Commented Apr 17, 2010 at 18:41
  • 4
    4 precise and distinct questions, like a homework! Commented Apr 17, 2010 at 18:42

1 Answer 1

4
  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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.