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

What is immutability in java?

614


Can you use abstract and final both with a method?

577


What is the difference between multiple processes and multiple threads?

578


what is meant by Byte code concept in Java?

604


What is a variable declaration?

531






What do you mean by boolean?

580


How can you set an applet’s height and width as a percentage?

525


How is Object Oriented Programming different from Procedure Oriented Programming?

599


What is the difference between static class and normal class?

496


What is the private method modifier?

594


How to convert string to byte array and vice versa?

592


How can you traverse a linked list in java?

694


What is methodological theory?

534


What are the new features in java 8? Explain

565


Explain serialization and deserialization in java?

569