I have a doubt regarding how memory is allocated for instance objects in JAVA. Can you please answer the following questions.  How is memory allocated for methods in a class (both static and non-static)?  Suppose I have an inner class within an enclosing classes, is memory allocated for the inner class too or unless its instantiated?  How come the inner class can access instance variables inside the enclosing class and NOT vice-versa? Kindly reply in detail. Thanx a lot in advance. regards, Sam.
. Primitive values are always located on the stack. Reference objects are created and live on the heap, while each's reference variable lives on the stack like the rest of the primitives (assuming it is being used somewhere). (Sorry for the incorrect term-usage there, if it applies.) Static or non-static? Huh? A method of execution is a method of execution and the rules will always apply concerning where things live and die (ie heap or stack). So, to correct you wording ... you should have said "how is memory for variables allocated and where for some methods..." . Inner classes are just regular classes that are um .. inner'ed. So, like all the other cool classes, they're just blueprings for objects which you will eventually create (on the heap) and only then will you be using memory due to your inner class. Technically, however, there is an actual "class object" floating around somewhere for your inner class so if you had static members in there (variables) it would incur some memory usage. . Think of an enclosing class and its inner class as a uni-directional association. The child needs to know who its daddy is, but the daddy don't care (paraphrase). If you really needed to get at an inner class instance's data, you could store it in a regular ol' instance variable in the enclosing class and invoke methods on it just as you normally would. Hm, yeah I guess that's about it. I should go to bed -- certification test in the morning. Hope my rambling helps you though.