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


Please Help Members By Posting Answers For Below Questions

What are the two basic ways in which classes that can be run as threads may be defined?

554


What is the difference between static (class) method and instance method?

579


What is a layout manager and what are different types of layout managers available in java awt?

731


What is yield () in java?

484


Does isempty check for null?

563






What is * argv?

710


What is the use of default method in interface in java? Explain

553


What are conditionals and its types?

592


Can singleton class be inherited in java?

518


Explain the difference between transient and volatile in java?

580


What is meant by tab pans?

652


What is reverse function?

577


What is a finally block? Is there a case when finally will not execute?

553


What is linkedlist in java?

512


What is the symbol for line break?

612