• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface question

 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think interface does not contain any variable, they contain constants only, and constants are not variables.
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.....
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, these type of ambiguous questions are not there.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sachin Adat
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic