Package Com.victor.test;import Java.util.random;public class Staticandfinaltest {private static random Rand = new Random ( ;p rivate static int statica = Rand.nextint (+);p rivate final int finalb = Rand.nextint (+);p rivate static final int s Taticfinalc = Rand.nextint (+);p ublic static void Main (string[] args) { staticandfinaltest saft1 = new Staticandfina Ltest (); System.err.println ("Saft1.statica:" + saft1.statica); System.err.println ("Saft1.finalb:" + saft1.finalb); System.err.println ("Saft1.staticfinalc:" + saft1.staticfinalc); System.err.println ("---------------------------------"); Staticandfinaltest saft2 = new Staticandfinaltest (); System.err.println ("Saft1.statica:" + saft2.statica); System.err.println ("Saft1.finalb:" + saft2.finalb); System.err.println ("Saft1.staticfinalc:" + Saft2.staticfinalc);}
}
The result of the operation is:
Saft1.statica:58saft1.finalb:93saft1.staticfinalc:55---------------------------------Saft1.statica: 58saft1.finalb:61saft1.staticfinalc:55
This is because it is static and is initialized at mount time instead of every time a new object is created.
The difference between static,final and static final in Java