Content deleted Content added
m spelling |
+example code |
||
Line 2:
A '''final [[Class (computer science)|class]]''' cannot be [[Subclass (computer science)|subclassed]]. This is done for reasons of security or efficiancy. Accordingly, many of the Java standard library classes are final, for example [http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html java.lang.System] and <code>[[java.lang.String]]</code>. All methods in a final class are implicitly final.
Example:
public final class MyFinalClass {...}
A '''final [[Method (computer science)|method]]''' cannot be [[Method overriding (programming)|overridden]] by subclasses. This is done for reasons of efficiancy, since the method can then be placed [[Inline function|inline]] wherever it is called.
Example:
public class MyClass {
public final myFinalMethod() {...}
}
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 variable|Local variables]] (for example, variables in loops) cannot be declared final.
Example:
public class MyClass {
public final float PI = 3.1415;
}
[[Category:Java programming language]]
|