Runtime vs compile time memory allocation in java
问题 I am confused regarding whether memory allocation in java occurs at run time or compile time. For example: class Test{ int a; public Test(){ a=10; } }; // somewhere else Test t = new Test(); Is a allocated at run time or at compile time? If at compile time, how is it possible as java runs on a VM which directly takes compiled .class files? Also: when is a assigned the value 10 ? how does it work for reference variable t ? Thanks. 回答1: Compile time no memory allocation happens. Only at load