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 are the two basic ways in which classes that can be run as threads may be defined?
What is the difference between static (class) method and instance method?
What is a layout manager and what are different types of layout managers available in java awt?
What is yield () in java?
Does isempty check for null?
What is * argv?
What is the use of default method in interface in java? Explain
What are conditionals and its types?
Can singleton class be inherited in java?
Explain the difference between transient and volatile in java?
What is meant by tab pans?
What is reverse function?
What is a finally block? Is there a case when finally will not execute?
What is linkedlist in java?
What is the symbol for line break?