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
how to create multithreaded program? : Java thread
Why we use methods in java?
Can we execute a program without main?
What is off heap memory?
Explain about wait() method?
Is java se open source?
Can you add null to a list java?
What is difference overloading and overriding?
Explain about arraylist?
What is array size in java?
What is passed by reference and pass by value ?
What are pass by reference and pass by value?
What do heavy weight components mean in java programming?
What is java basic concept?
How does hashset works in java?