Final (Java): Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 53:
public class Sphere {
 
// piPi is a universal constant, about as constant as anything can be.
public static final double PI = 3.141592653589793;
 
Line 62:
 
Sphere(double x, double y, double z, double r) {
radius = r;
xPos = x;
yPos = y;
zPos = z;
}
 
Line 156:
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:
 
if (number % 2 == 0) {
isEven = true;
}
 
Line 181:
 
if (number % 2 == 0) {
isEven = true;
}
 
Line 208:
 
==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: