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 java uses the string and stringbuffer classes?
What exactly is java?
What is exception in java?
How do you sort in ascending order in java?
What is linkedlist in java?
What is an object in java and how is it created?
why would you use a synchronized block vs. Synchronized method? : Java thread
Can a private method of a superclass be declared within a subclass?
What is java util collection?
How will you get the platform dependent values like line separator, path separator, etc., ?
What is the difference between final, finally and finalize()?
How to use string tokenizer class.
Is there any case when finally will not be executed?
How does split work in java?
Can an interface extend another interface?