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
What happens if we override private method?
Under what conditions is an object’s finalize() method invoked by the garbage collector?
how many types of Inheritance?
What is the difference between throw and throws in java?
What is a singleton puppy?
What is skeleton and stub? What is the purpose of those?
What is the difference between the paint() and repaint() methods?
What is the final keyword in java?
Can we force garbage collector to run ?
In a class implementing an interface, can we change the value of any variable defined in the interface?
How to display names of all components in a Container?
What is an interface in java? Explain
whatis Home interface and Remoteinterface? with example?
Explain the purpose of garbage collection in Java?
What is the use of singleton class?