what is finalmethod & final variable with example?
Answer Posted / aditi
Final method cannot be overridden by subclasses. This is
used to prevent unexpected behavior from a subclass
altering a method.
Example:
public class MyClass {
public final void myFinalMethod() {...}
Final Variable, it can only be assigned to once and only in
the constructor of class if variable is not a reference to
pther object.
Example:
public class Sphere {
public static final double PI = 3.141592653589793; //
this might as well be a constant
public final double radius;
public final double xpos;
public final double ypos;
public final double zpos;
Sphere(double x, double y, double z, double r) {
radius = r;
xpos = x;
ypos = y;
zpos = z;
}
| Is This Answer Correct ? | 10 Yes | 0 No |
Post New Answer View All Answers
what is anonymous class in java?
Explain the difference between jvm and jre?
How many types of exception can occur in a java program?
What is floor in java?
What is parseint?
What is a "pure virtual" member function?
What do you mean by pointer value and address?
Where is const variable stored?
What is a java applet? What is an interface?
What is static method with example?
What is a final class in java?
What is singleton class in ruby?
Can java program run without jre?
List some important characteristics on jre
How do you find the maximum number from an array without comparing and sorting?