I thought that an interface only contains behavior and cannot contain state. If this is correct, is String NAME not considered state?
Interface can have state??
Under discussion
Comments (7)
- Popular
- New
- Old
You must be signed in to leave a comment
Sela
17 July 2020, 13:22
it may not be considered as object's state because it is static by default meaning exists before even object was created
+2
Alexander Shtunder
14 August 2019, 10:06
All fields in the interface are public static final, that is, they are constants. Therefore, if your String NAME is not a constant, it is undesirable to use it in the interface.
+1
Jay
14 August 2019, 12:55
So, legal but not best practice?
0
Alexander Shtunder
16 August 2019, 07:33
All right
0
Johannes
22 March 2020, 07:26
Sorry, you're not making sense to me ? (I am the one not understanding, it's not you).
NO fields in "SimpleObject" are marked as "public" or as "static" or as "final" ?
And in "Button", the String is declared as "final", yes, but not public or static.
Why does that make a difference ? Please explain ? Why can I even declare String again (it's already defined in the parent interface), and why do I need to have a method with an object, if it's not an abstract interface ? This stuff keeps making no sense, no matter how many examples I complete.
0
Sela
17 July 2020, 13:15
declaring the same name of field in subclass (or child interface) as in superclass, so superclass field is hidden means field hiding and is almost always a sign of bad code. you may console yourself with this.
+2
Sela
17 July 2020, 13:27
and it is still interface meaning abstract data type although having a parent
+2