Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface Theory

 
Yogesh Chhawasaria
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All Got this one wrong at the javaprepare site Mock test
http://www.javaprepare.com/quests/test.html
Which of the following are true about interfaces. Select the two correct answers.
A Methods declared in interfaces are implicitly private.
B Variables declared in interfaces are implicitly public, static, and final.
C An interface can extend any number of interfaces.
D The keyword implements indicate that an interface inherits from another.
I was sure that
C is corect
A is incorrect
Took a guess from the B and D
Can anyone elaborate the B part
Plz also post a good link for interface theory.
Thanks in advance.
P.S. I got a score of 87.75 in that test Hows That good enuf.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the JLS, §9.3 Field (Constant) Declarations, you'll see this:

Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields.

Interfaces are not classes - they are designed to provide an "interface" for dealing with an object. As some methods require constants for interaction, it is permitted to declare constants within an interface. However, you can not instantiate an interface so there is no reason for having a non-constant value (such as an instance variable) within an interface. Therefore, all fields declared within an interface are implicity public, static, and final.
I hope that helps,
Corey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic