What is static in Java
Static in Java is related to class, if a field is static means it belongs to class, similarly static method belongs to classes and you can access both static method and field using class name e.g. if
count field is static in
Counter class than you can access it as
Counter.count, of course subject to restriction applied by access modifier e.g.
private fields are only accessible in class on which they are declared, protected fields are accessible to all classes in same package but only accessible in sub class outside package. See
private vs protected vs public for complete details on access modifier. Similarly if you have a static method
increment() in
Counter class which increment counter than you can call it as
Counter.increment(). There is no need to create an Object of Counter class to access either
static method or static field, this is main difference between static and non static members.