Trivial question about interfaces
Now, I'm aware that, by default, interfaces are final and static. static because they cannot be instantiated, and final because I can only declare constant variables within them. My questions are: - Do I need to explicitly declare "public final static interface", or I just declare "public interface" and it is set final and static implicitly? -If I do need to declare it explicitly, do I need to do that only if I want to have constant values within it, or in any case (e.g. interface with only functions) ?
9/1/2017 3:17:39 PM
Michael Vigato
4 Answers
New AnswerYou don't have to do so. Take the following segment for example: public interface MyInterface { public String hello = "Hello"; public String bye = "Goodbye"; public void sayHello(); public void sayBye(); } This is a perfectly valid declaration of an interface. Cheers.
You would not be able to as you can think of the line: public String hello = "Hello"; as public static final String hello = "Hello";
So if I was willing to modify myInterface.hello, I would not be able, because that's final. right?