Content deleted Content added
No edit summary |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 10:
Example:
<syntaxhighlight lang="java">
public final class
// ...
}
// Forbidden
public class DerivedClass extends FinalClass {
// ...
}
</syntaxhighlight>
Line 21 ⟶ 26:
Example:
<syntaxhighlight lang="java">
public class Base {
public
▲ public final void m2() {...}
public static
public static final void m4() { ... }
}
public class Derived extends Base {
public void
▲ public void m2() {...} // forbidden
public static void m3() { ...
public static void m4() { ...
}
</syntaxhighlight>
Line 53 ⟶ 56:
public class Sphere {
//
public static final double PI = 3.141592653589793;
Line 62 ⟶ 65:
Sphere(double x, double y, double z, double r) {
}
Line 156 ⟶ 159:
final boolean hasTwoDigits;
if (number >= 10 && number < 100) {
hasTwoDigits = true;
}
if (number > -100 && number <= -10) {
hasTwoDigits = true; // compile-error because the final variable might already be assigned.
}
</syntaxhighlight>
Line 168 ⟶ 171:
if (number % 2 == 0) {
isEven = true;
}
Line 181 ⟶ 184:
if (number % 2 == 0) {
isEven = true;
}
Line 208 ⟶ 211:
==C# analogs for final keyword ==
[[C Sharp (programming language)|C#]] can be considered as similar to Java, in terms of its language features and basic syntax: Java has JVM, C# has .Net Framework; Java has bytecode, C# has MSIL; Java has no pointers (real memory) support, C# is the same.
Regarding the final keyword, C# has two related keywords:
|