Variable: string test = "ABC"; // nothing to say
Constant: Use the keyword final in Java to define the constant final string test = "ABC ";
A constant can only be assigned a value once and cannot be modified after being assigned a value.
Static variable: static string test = "ABC"; // class member, which belongs to the class and does not belong to any object. Class is loaded into the memory for the first time.
For example:Class employee {<br/> private string userid; <br/> Private Static string roleid = "12"; <br/>}
Each object has its own userid, but all instances of this class will share a roleid. If there are 1000 objects, there will be 1000 userids, but there is only one static domain roleid. The static domain roleid exists even if no new object is created.
Static constants: Java uses static final to define static constants.
Example: public static final test = "ABC ";
Static constants can be accessed without a new object, but cannot be modified.
Another static constant used multiple times is system. Out. It declares in the system class:
Public class system {<br/> Public static final printstream out =...; <br/>}
Therefore, we can directly access the out attribute without a new system object.