Class/static variables − class/static variables belong to a class, just like instance
variables they are declared within a class, outside any method, but, with the static
keyword.
They are available to access at the compile time, you can access them before/without
instantiating the class, there is only one copy of the static field available throughout
the class i.e. the value of the static field will be same in all objects.
You can define a static field using the static keyword.
=============================================================================================
System.out.println(MyClass.data);
i.e. referring a variable using static reference implies to referring using the class name.
But, to access instance variables it is a must to create an object,
these are not available in the memory, before instantiation.
Therefore, you cannot make static reference to non-static fields(variables) in Java.
If you still, try to do so a compile time error is generated saying “non-static variable
math cannot be referenced from a static context”.