peakit peakit - 1 month ago 7
Java Question

Why are all fields in an interface implicitly static and final?

I am just trying to understand why all fields defined in an Interface are implicitly

static
and
final
. The idea of keeping fields
static
makes sense to me as you can't have objects of an interface but why they are
final
(implicitly)?

Any one knows why Java designers went with making the fields in an interface
static
and
final
?

Answer

An interface can't have behavior or state because it is intended to specify only an interaction contract, no implementation details. No behavior is enforced by not allowing method/constructor bodies or static/instance initializing blocks. No state is enforced by only allowing constants. A constant in Java is defined by a static final field (and by convention the name uses UPPER_CASE_AND_UNDERSCORES).