The static modifier is used to create variables and methods that will exist
independently of any instances created for the class. All static members exist
before you ever make a new instance of a class, and there will be only one copy of a static member regardless of the number of instances of that class.
In the below cases we can not mark as static :
independently of any instances created for the class. All static members exist
before you ever make a new instance of a class, and there will be only one copy of a static member regardless of the number of instances of that class.
In the below cases we can not mark as static :
- Constructors (makes no sense; a constructor is used only to create instances)
- Classes (unless they are nested)
- Interfaces
- Method local inner classes
- Inner class methods and instance variables
- Local variables
Posted in: