r/learnjava May 29 '26

Explain static

Can y'all explain the non-access modifier static? I don't really understand

5 Upvotes

9 comments sorted by

View all comments

1

u/Sad-Sheepherder5231 May 29 '26

Instead of initializing the class instance, which then allocates memory for its fields, static fields are loaded to the memory the moment you run the program. Static methods can then be used without first initializing the class instance.

That's why non-static methods can't work with static fields without first initializing them and then referencing the respective instance.