This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Question 6. An Interface can never be private or protected. Answers True or False ? The answer is False. I don't understand in what situation the interface could be private or protected? Question 59. Interface methods can be declared with the following modifiers 1 public 2 none (i.e., no access modifier). 3 private. 4 static 5 native 6 synchronized. The answer is 1 and 2. But according to <<Exploring JAVA>> by Patrick Niemeyer & Joshua Peck, it says:"The methods of an interface are always considered public"(p167). So could 'none' be a modifier of interface? Question 60. Which of the following are true about the class defined inside an interface 1 it is not possible in the java Laungage. 2 The class is always public. 3 The class is always static. 4 the class methods cannot call the methods declared in the interface. Answer is 2, 3&4. Could sb. give me an example how to create the instance class? Should we implement the interface first?
5 the class methods can call only the static methods declared in the interface.
Hi Yi, I could think of 1 zillion reasons why my interfaces should be private or protected. I really don't like sharing with strangers! The question doesn't require you to explain when an interface can be private or protected, just so that you know the JVM doesn't restrict access modifiers on interfaces. Interface methods are always considered public. Think of it this way: If I don't place an accessor on an interface method the compiler will place "public" there. The same as default constructors. The trick here is that none doesn't specify default as in class methods. Regards, Manfred.
Joined: Jan 09, 2001
Hi Yi, An example of class being define inside interface. From the answers you can deduce that the class will be static and public. What does that mean? It means that you don't need an interface object to create the class! See code following.
Hi Yi, Just to add to Manfred's response. You can define an interface as a member of a class; in which case it may be private or protected.
The above won't cause an error. The question is just trying to emphasize that not all interfaces are public. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform