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)
public class MyFinal {
  final double PI = 3.14;
  public static void main( String[ ] args ) {
    MyFinal myObj = new MyFinal( );
    myObj.PI = 3.14159; 
    System.out.println( myObj.PI );
  }
}
Output:           Result:

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

      override
      synchronized
      transient
      volatile
        Result:




      “The easiest time to add insult to injury is    
      when you’re signing somebody’s cast.”    
      – Demetri Martin