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 number data type in java?
What is difference between adapter class and listener?
Explain the difference between hashmap and hashtable in java?
How do you achieve polymorphism in java?
What are 4 pillers of object orinted programming?
What is the common usage of serialization? What exceptions occur during serialization?
What is java lang string?
What is the relationship between class and object?
What are the basic control structures?
What variables are stored in stack?
What is java Applet?
What does t in java mean?
Why is a string immutable?
Can you override private or static method in java?
Write code to implement bubble sort in java?