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 replacement method of stop() of thread

8 Answers   IBM, TCS,


write a progam hashmap & hashtable?

2 Answers   IBM,


Is there any sort function in java?

0 Answers  


What are the classes of java?

0 Answers  


What are data types in programming?

0 Answers  






what is an virtual function

2 Answers   TCS,


Is upper case in java?

0 Answers  


What is java lang string?

0 Answers  


Difference between start() and run() method of thread class?

0 Answers  


suppose in a class there is a code like this: { Set hs=new Hashset(); hs.add(new Emp("kathy",1000)); hs.add(new Emp("kathy",2000)); } how can u avoid the above code in your class as set won't allow duplicate objects?

3 Answers  


When can you say a graph to be a tree?

0 Answers   Amazon,


Write a program to solve producer consumer problem in java?

0 Answers  


Categories