The final field cannot be assigned, for an interface

Interfaces can only include constants, not general-purpose variables. Interfaces should only contain constants if they're genuinely relevant to the rest of the interface, and they should use SHOUTY_CASE as per any other constant. It sounds like LargeProduct shouldn't have a constant called height - but instead, your implementation should declare the height field.

Note that interfaces are meant to be APIs, showing the abilities of types. Fields shouldn't be part of the API - they're an implementation detail. After all, who's to say that you'll write getHeight and setHeight based on a simple variable? Those methods could query a database, or delegate to an instance of some other type. The consumer of the interface shouldn't know or care about that.

For further information about fields in interfaces, I suggest you read section 9.3 of the Java Language Specification:

Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields.


By default fields (member variable) in interface are public static final

and you don't have setter for final

Tags:

Java

Interface