Source http://www.wbrogden.com/ Which of the following statements about interfaces is correct?
A Due to Java's principle of single inheritance, a class declaration can only name one interface.
B All methods in an interface have default accessibility unless declared otherwise.
C All methods in an interface have public accessibility.
D An interface may not contain any variables.
Your recorded answer C,D
A - No, a class declaration may include multiple interfaces.
B - No, all methods in an interface are implicitly public.
C * Yes, all methods in an interface are implicitly public, no matter how the interface itself is declared.
D - No, interfaces may define static final variables.
Why is D not right? How should the word "may" be interpreted? I think "may not contain" means it is not compulsory.
Had it been "must not contain" then its incorrect about interfaces, hence not in the answer.
I think interface does not contain any variable, they contain constants only, and constants are not variables.
Joined: Sep 03, 2007
Now that's a whole new way of looking at the question.........
Do such type of questions come up in the actual exam where questions(or answers) are ambiguous?
I am still not convinced with the reply though.....
Joined: Oct 16, 2008
No, these type of ambiguous questions are not there.
I can see how "may not contain" could be interpreted as you did, but it means indeed "can not contain" or "must not contain".
I don't think the question is aimed at the difference between variable and constant (which in any case is not a term that's used from a Java specification point of view). Using the term "field" instead of "variable" might have been a bit clearer.
You might want to alert William (who's a moderator here) to this discussion.
Ping & DNS - updated with new look and Ping home screen widget