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
Which list is sorted in java?
In a container there are 5 components. I want to display all the component names, how will you do that?
Does unicode support all languages?
Java is pass by value or pass by reference? Explain
Tell me the latest versions in java related areas?
What mechanism does java use for memory management?
Can arraylist contain null values?
What is the latest java version?
What is data type example?
Is string passed by reference in java?
What do negative exponents mean?
Explain importance of inheritance in java?
Can an interface be final?
What is the purpose of encapsulation?
Under what conditions is an object’s finalize() method invoked by the garbage collector?