Access specifiers / Access Modifiers / Visibility Modifiers
Below matrix provides the details about access specifier and their scope on variable, methods and classes.
Static :
- Only one copy will be created in memory (i.e same copy will be available across all the objects created for a particular class)
- Can be applied to variables, methods, inner classes and blocks.
- Static members will be loaded along with Class loading.
- Static members can also be accessed through Class Name along with through the object.
- non-static members can not be accessed inside static methods directly.
- non-static members can be accessed inside static methods by creating object of the non-static member of the class.
- static members can be accessed inside non static members directly.