"""
A static variable is common to all the instances (or objects) of the class because it is a class level variable. In other words you can say that only a single copy of static variable is created and shared among all the instances of the class. Memory allocation for such variables only happens once when the class is loaded in the memory.
Static variable can be accessed directly in a static method.
Static variable initialization
- Static variables are initialized when class is loaded.
- Static variables are initialized before any object of that class is created.
- Static variables are initialized before any static method of the class executes.
Final variable always needs initialization, if you don’t initialize it would throw a compilation error.
"""
No comments:
Post a Comment