Final (Java)

This is an old revision of this page, as edited by Ezrarez (talk | contribs) at 14:38, 1 February 2006 (+link local variable). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In the Java programming language, the final keyword is used in several different contexts to define an entity which cannot later be changed.

A final class cannot be subclassed. This is done for reasons of security or efficiancy. Accordingly, many of the Java standard library classes are final, for example java.lang.System and java.lang.String. All methods in a final class are implicitly final.

A final method cannot be overridden by subclasses. This is done for reasons of efficiancy, since the method can then be placed inline whereever it is called.

A final variable is a constant. It must be assigned a value at declaration, and the variable can later be used but not assigned a new value. Local variables (for example, variables in loops) cannot be declared final.