All the objects of a class share the static variable. But when is the memory allocated for the static variable? Is it when the first object is created for the class? Or does it happen even before any instance for the class is created? Also instance variable is allocated memory at runtime. The memory for static variable is allocated at runtime or compile time?
When the class is loaded, at runtime. You can find the details here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With