+ 1

How does memory management takes place for static and non-static variables ?

My trainer said that static variables get memory under class and non-static variables get memory under object. But I have studied that a class is a logical structure of object and also object is the physical existence of class. If it is a logical structure then how does static variables get memory??

23rd Sep 2016, 3:37 AM
Pavan Teja
Pavan Teja - avatar
2 Respostas
+ 1
When you create an instance of an object/class, a memory block will be allocated in heap for this class and a reference to this object will be created in stack. All local variables (variables that created in methods) lives their short life in stack. Memory management doesn't care if an object is static or non-static. Please google heap and stack.
10th Feb 2017, 4:24 AM
Sinan Ceylan
Sinan Ceylan - avatar
- 1
a static variables is stored in the static pool. non-static variables are stored in heap. local variables are stored in stack. that is the reason why,we cannot access a local variable globally.
23rd Sep 2016, 7:10 AM
Soumadeep Tapadar
Soumadeep Tapadar - avatar