In the Java programming language, the final keyword is used in several contexts to define an entity that can only be assigned once. Once a final variable has been assigned, it always contains the same value. If a final variable holds a reference to an object, then the state of the object may be changed by operations on the object, but the variable will always refer to the same object (this property of final is called non-transitivity). This applies also to arrays, because arrays are objects; if a final variable holds a reference to an array, then the components of the array may be changed by operations on the array, but the variable will always refer to the same array. Final classes A final class cannot be subclassed. As doing this can confer security and efficiency benefits, many of the Java standard library classes are final, such as and . Example: public final class MyFinalClass {...} public class ThisIsWrong extends MyFinalClass {...} // forbidden Final methods A final method cannot be overridden or hidden by subclasses. This is used to prevent unexpected behavior from a subclass altering a method that may be crucial to the function or consistency of the class. Example: public class Base { public void m1() {...} public final void m2() {...} public static void m3() {...} public static final void m4() {...} } public class Derived extends Base { public void m1() {...} // OK, overriding Base#m1() public void m2() {...} // forbidden public static void m3() {...} // OK, hiding Base#m3() public static void m4() {...} // forbidden } A common misconception is that declaring a method as final improves efficiency by allowing the compiler to directly insert the method wherever it is called (see inline expansion). Because the method is loaded at runtime, compilers are unable to do this. Only the runtime environment and JIT compiler know exactly which classes have been loaded, and so only they are able to make decisions about when to inline, whether or not the method is final. Machine code compilers that generate directly executable, platform-specific machine code, are an exception. When using static linking, the compiler can safely assume that methods and variables computable at compile-time may be inlined. Final variables A final variable can only be initialized once, either via an initializer or an assignment statement. It does not need to be initialized at the point of