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 a variable simple definition?

1 Answers  


Can you give few examples of final classes defined in java api?

1 Answers  


What is the difference between delete and delete[]

4 Answers   Amazon,


What is return type in java?

1 Answers  


Why main method is called first in java?

1 Answers  


What is Hierarchy of exception?

1 Answers   Amdocs,


How do you implement tree mirroring in java?

1 Answers   EXL, HCL,


What are the advantages of compiled language?

1 Answers  


How is garbage collection controlled?

1 Answers  


when there is a need of jvm then how we can say that java is a platform independent language?

3 Answers  


how to accept integer array in java

2 Answers   Tech Guru,


what is encapsulation in java? Explain

1 Answers  


Categories