Why we should declare the variables as static and final in
interfaces?
Answer Posted / nc
It is automatic static and final even if you don't declare it.
Why? Because when a class implements these interfaces, these
variables must be able to be accessed by static and
non-static methods. Also as these variables are specific to
any class instances(i.e. at the same time many classes can
implement these interfaces), they must have the same value
across the implementing classes.
Also if you want to load the value of certain values at the
application start up and all implementing classes wants
these values unchanged, then these must be static and final.
So they are static and final.
| Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
How to convert string to char and vice versa?
Explain the use of volatile field modifier?
What is difference between final and finally in java?
What is nan in java?
What is stringreader?
Is char a data type in java?
What is the base class of all classes?
Difference between arraylist and vector.
What is a cup of java?
What do you know about the garbage collector?
What does it mean that a method or field is “static”?
What is the transient keyword?
What does nullpointerexception mean?
How to reverse a string in java?
Which is dependent variable?