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
What is immutability in java?
Can you use abstract and final both with a method?
What is the difference between multiple processes and multiple threads?
what is meant by Byte code concept in Java?
What is a variable declaration?
What do you mean by boolean?
How can you set an applet’s height and width as a percentage?
How is Object Oriented Programming different from Procedure Oriented Programming?
What is the difference between static class and normal class?
What is the private method modifier?
How to convert string to byte array and vice versa?
How can you traverse a linked list in java?
What is methodological theory?
What are the new features in java 8? Explain
Explain serialization and deserialization in java?