Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is the memory allocated for a static variable in java?

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?

like image 595
Amriteya Avatar asked Jun 29 '15 07:06

Amriteya


1 Answers

When the class is loaded, at runtime. You can find the details here.

like image 123
Kayaman Avatar answered Sep 18 '22 00:09

Kayaman