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 space character in java?

0 Answers  


can we have function for truncating the sign as like abs in oracle.

1 Answers  


What is arrays aslist in java?

0 Answers  


Why transient variables wont participate in serialization?

2 Answers  


What is the purpose of final keyword and when to use it?

0 Answers  






What do you understand by access specifiers in Java?

0 Answers   Genpact,


INTERVIEW QUESTION FOR ANDROID

0 Answers  


Is java call by reference?

0 Answers  


How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters in java programming?

0 Answers  


why the abstract class has default constructor?

2 Answers  


can we write two same methods in outer class and innerclass.

1 Answers   3i Infotech,


How many functional interfaces does java 8 have?

0 Answers  


Categories