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
How do you differentiate abstract class from interface?
Explain restrictions for using anonymous inner classes?
who can i handle multiple client in RMI
What is meant by string is immutable?
How do you sort arraylist in descending order?
What are packages in java?
Can main() method in java can return any data?
What is widening and narrowing in java? Discuss with an example.
Explain inheritance in java?
What are the types of casting?
What is the purpose of using the java bean?
Explain hashset and its features?
Is java a pure object oriented language?
What are three advantages of using functions?
What are annotations in java?