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
List primitive java types?
What does || mean in code?
What is the role of garbage collector in java?
How does multithreading take place on a computer with a single cpu in java programming?
What is the instance of an object?
What is a prefix function.write down a code to compute prefix function.
What is map in java?
How to sort numbers in java without array?
Which number is denoted by leading 0x or 0x in java?
Why is stringbuffer called mutable?
how would you implement a thread pool? : Java thread
What is the main function in java?
Is it possible to cast an int value into a byte variable? What would happen if the value of int is larger than byte?
What is floor math?
What is the argument in java?