/**
Use of *final Keywords
* @author lihaiming
*email:[email protected]
* Keyword final can be decorated with properties, methods, classes
* When modifying a property, the final modified variable is a constant
* When modifying a method, the method is not overridden by the quilt class
* Class is not inherited when class is modified
*/
public class testfinal{
When the final modifier variable is constant, it cannot be assigned again;
private final int i=100;
Static is a global variable
private static int j=50;
private final int ID;
Final modified reference type; non-modifiable space;
Final Li L = new Li ();
Use the final, static keyword to modify the variable, the variable is a global constant, can only invoke the use, can not assign value and other operations;
Public testfinal () {
Id=++j;
}
public static void Main (string[] args) {
testfinal tf = new testfinal ();
SYSTEM.OUT.PRINTLN (TF. I);
System.out.println (J);
System.out.println ("------------------");
testfinal TF1 = new Testfinal ();
Testfinal TF2 = new Testfinal ();
System.out.println (tf1.id);
System.out.println (tf2.id);
System.out.println ("------------------");
System.out.println (Tf.l.geti ());
Tf.l.seti (56);
System.out.println (Tf.l.geti ());
}
}
Class li{
public int i=10;
public int j=12;
Public Li () {}
public void SetI (int i) {
This.i=i;
}
public int Geti () {
return i;
}
}
Program results:
100
51
------------------
52
53
------------------
10
56
Java Basics (2)--use of the keyword final