a static variable belongs to the class, and not to the object (instance). A static variable can be accessed directly by class name and does not need any object. it saves space by not having variables for the same data for each class.
Syntax : <class-name>.<variable-name>
public class AA{
static int a =10;
}
You may call
System.out.println(AA.a);
System.out.println(aObject.a);
There are no differences between the two calls, but maintain a coding convention to save more readbale
source
share