Final keyword features:
1. Can be used to modify variables, methods, classes.
2. The modified variable is a constant. Once assigned, it cannot be modified (constants are typically used in conjunction with the static keyword)
3. The modifier class cannot be inherited for this class 4. The modification method represents that the secondary method cannot be overridden
public class Finaldemo {public static void main (string[] args) {//TODO auto-generated method stubfinal Demoa DA = new Dem OA ();D emob DB = new Demob ()//da = new Demoa; If the final decoration is added, DA can no longer modify the reference Da.testa ();d B.testa ();}} /*final*/class demoa{//If Final is added, demob can not inherit demoapublic final int a = 1;public int b =2;public/*final*/void TestA () {/ /If Final is added, the Testa in the demob can not rewrite the testa//a++ in Demoa; Because the final modified variable A is a constant, it cannot be modified System.out.println (a);} public void Testb () {System.out.println (b);}} Class Demob extends demoa{public int a = 1;public int b =2;public void TestA () {System.out.println (a);} public void Testb () {System.out.println (b);}}
Java Inheritance-final keyword usage