The final Keyword


The final keyword is a non-access modifier used for classes, attributes, and methods, which makes them non-changeable (also impossible to inherit or override). The final keyword is useful when you want a variable to always store the same value, like PI (3.14159...).

MyFinal.java (the final keyword)
1public class MyFinal {
2  final double PI = 3.14;
3  public static void main( String[ ] args ) {
4    MyFinal myObj = new MyFinal( );
5    myObj.PI = 3.14159;
6    System.out.println( myObj.PI );
7  }
8}
Output:           Result:

Review: Non-Access Modifier
    Which non-access modifier for attributes and methods does not exist?

      override
      synchronized
      transient
      volatile
        Result: