0
public interface A 
{

    public final int a = 0;

}

Many books say that all variables (constants) in an interface are implicitly public static final yet when I type the above statement explicitly but do not include the keyword static it compiles with no errors and can be referenced by the static way, A.a which indicates that it is still static.

Is it static or not, as to me it has to be since you cannot instantiate an interface, as if you had this "instance" variable then you could therefore never access the data member "a" as it is a non-static field.

1
  • 1
    ... you can also leave the public keyword. Commented May 6, 2013 at 20:15

1 Answer 1

4

Many books say that all variables (constants) in an interface are implicitly public static final

Yes, and what you're observing is exactly consistent with that. The key word is implicitly: it is a static variable whether or not you write the word static.

Sign up to request clarification or add additional context in comments.

1 Comment

answer = answer.replace("behaves like", "is");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.