This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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.
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
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