I am wondering when to use static methods? Say if I have a class with a few getters and setters, a method or two, and I want those methods only to be invokable on an instanc
Static methods and variables are controlled version of 'Global' functions and variables in Java. In which methods can be accessed as classname.methodName()
or classInstanceName.methodName()
, i.e. static methods and variables can be accessed using class name as well as instances of the class.
Class can't be declared as static(because it makes no sense. if a class is declared public, it can be accessed from anywhere), inner classes can be declared static.