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


Please Help Members By Posting Answers For Below Questions

how to create multithreaded program? : Java thread

501


Why we use methods in java?

530


Can we execute a program without main?

531


What is off heap memory?

542


Explain about wait() method?

562






Is java se open source?

560


Can you add null to a list java?

577


What is difference overloading and overriding?

577


Explain about arraylist?

571


What is array size in java?

492


What is passed by reference and pass by value ?

576


What are pass by reference and pass by value?

525


What do heavy weight components mean in java programming?

517


What is java basic concept?

519


How does hashset works in java?

526