The main differences between static and non static variables are:
| STATIC VARIABLE | NON STATIC VARIABLE |
|---|---|
| Static variables can be accessed using class name | Non static variables can be accessed using instance of a class |
| Static variables can be accessed by static and non static methods | Non static variables cannot be accessed inside a static method. |
| Static variables reduce the amount of memory used by a program. | Non static variables do not reduce the amount of memory used by a program |
| Static variables are shared among all instances of a class. | Non static variables are specific to that instance of a class. |
| Static variable is like a global variable and is available to all methods. | Non static variable is like a local variable and they can be accessed through only instance of a class. |
Differences between static and non static variables in java.
Reviewed by Pappy
on
September 03, 2019
Rating:
No comments: