Final is a keyword in Java, previously thought C + + does not have this keyword, just checked, unexpectedly! Then Also Yes! It seems that the usage is similar.
Roughly divided into so many, by this thing modified the east, so far, can not be changed.
For example
1 function is modified, cannot be overwritten.
2 classes are modified, they cannot be inherited.
3 variables are modified, can only be assigned once, remember Oh, this and C + + static const is not the same, this thing can be declared, not necessarily to declare when the assignment, but only! Yes! Fu! Value! One! Times!.
On the Code
Final class animal{//Add here, the following inheritance will error OH public final int ff; That's it. {ff= 4;//You can assign a value with a code block}public Animal (int t) {//this.ff= t;//can also be assigned with a constructor System.out.println ("Create Animal");//TODO Auto-generated constructor stub}public final void Cry () {//Added here, the following cover also does not have the bird System.out.println ("wo~~~~~~~");} Public final void Run () {//But don't forget, although not rewritten, the System.out.println ("Runrunrunrunr") can be used as a make-up.}} Class Dog extends Animal{public dog (int t) {super (T); System.out.println ("Create Dog");//TODO auto-generated constructor stub}public void Cry () {run (); System.out.println ("wang~~~~~~" +ff);} Class Test{public static void Main (string[] args) {Dog dog = new Dog (3);d og.cry ();D og dog2 = new Dog (5);d og2.cry ();}}
That's it, the rest.
The final related stuff in Java