Why we should declare the variables as static and final in
interfaces?



Why we should declare the variables as static and final in interfaces?..

Answer / 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

More Core Java Interview Questions

What is the difference between compile-time polymorphism and runtime polymorphism?

0 Answers  


can two class in a code be public??if yes then how??

2 Answers  


Explain the importance of import keyword in java?

0 Answers  


What is internal variable?

0 Answers  


What is difference between jdk,jre and jvm?

0 Answers  


Explain about strings in java?

0 Answers  


what is the use of StringBuffer?

2 Answers   Accenture,


What enableEvents() method do?

1 Answers  


Can we sort hashmap in java?

0 Answers  


What is passing parameters in java?

0 Answers  


What is the significance of continue jump statement? Explain with an example.

0 Answers   Amdocs,


How do I run java on windows?

0 Answers  


Categories