When are static fields initialized? If I never instantiate a class, but I access a static field, are ALL the static blocks and private static methods used to instantiate private static fields called (in order) at that instant? or when app is started?
Asked
Active
Viewed 74 times
0
-
2For java: https://stackoverflow.com/questions/3499214/when-does-static-class-initialization-happen. We can assume it may be similar – Mohammed Aquib Azad Jan 27 '20 at 15:16
1 Answers
2
If you are using Java to develop your android applications the static fields are initialized when the app start and they are stored in the heap memory. If you want to access a static field you don't need an instance of a class you can access it using your class name ClassName.staticField example:
Person.staticAge
If you need more information, refer to this
static allocation in java - heap, stack and permanent generation

Jorge Arguedas Arrieta
- 131
- 1
- 9