When I create a new Object the JVM allocates a memory block on the heap, regardless of the data that might come along. It might contain variables, it might contain methods. Let us call this mainObject. My question is that if there is another object ; lets call it childObject defined inside this Class of mainObject will the JVM assign a new memory block at a different memory location and setup some internal pointer from mainObject to childObject or will it define the memory location of childObject inside mainObject only.
Details of main class
Public class mainClass{
public mainCLass(childClass childclass)
}
Now this main class's object is created
mainClass mainclass = new mainCLass(childclass2);
Now the question is when the mainclass is being created a memory allocation is happening on heap. This object also has childClass childclass being passed in the constructor. Now my question is where is this childclass object getting created. In the same memory location as mainclass or someother memory location. Kindly let me know if there is still some doubt.
Tx