The difference between static and non-static is only revealed if the value is initialized during runtime. Because the values during compilation are considered by the compiler to be phase
The same.
Packagethinking; Public classFinalData {//Can be Compile-time constants Final intI1 = 9; Static Final intI2 = 99; //Typical public constant: Public Static Final intI3 = 39; //cannot be Compile-time constants: Final intI4 = (int) (Math.random () *20); Static Final inti5 = (int) (Math.random () *20); Public voidprint (String id) {System.out.println (id+ ":" + "I4 =" + I4 + ", i5 =" +i5); } Public Static voidMain (string[] args) {FinalData fd1=NewFinalData (); FinalData FD2=NewFinalData (); Fd1.print ("Fd1"); Fd2.print ("Fd2"); }}
Note that for FD1 and FD2, the value of I4 is unique, but the value of i5 does not change due to the creation of another FinalData object
Change. That is because its properties are static and initialized at load time, rather than when each object is created.
Java final static and final differences