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
Is 0 a prime number?
Can a method be static?
Difference between doublesummarystatistics, intsummarystatistics and longsummarystatistics ?
What is the size of boolean variable?
List some features of the abstract class.
These static constructors are correct ? class A { statc intA() { } static A(int x,int y) { } static A(int x) { } }
What is the abstraction?
What is the purpose of garbage collection in java, and when is it used?
How do you sing an Applet ?
What does || || mean in math?
What is defined as false sharing in the context of multithreading?
What is indexof?
What do you mean by constant time complexity?
Explain the features of java?
What is immutable data?