This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Hello All, I was wondering about the following question: (from Dan Chisolm's test) Which of the following are modifiers that can be applied to an interface that is a member of a directly enclosing interface? a. abstract b. implements c. final d. private e. protected f. public
I would definately say a,c,f but the answer is a,c. When an interface declares a member of itself, doesn't all fields become inherently public,static,final, and all methods are public,abstract. I would think that declaring an nested interface/class would also make them inherently public,abstract, and final, since they would be declared in the scope of the interface. What am I missing here? Zak Nixon
Zak, The answers on my exam are actually a and f. My exam does not list option c among the correct answers. The reason is because the modifier, final, is never applicable to an interface declaration. The explanation provided by my exam is as follows.
All interfaces are implicitly abstract. The explicit application of the abstract modifier to an interface declaration is redundant and is strongly discouraged. The declaration of an interface within the body of an enclosing class or interface is called a member type declaration. Every member type declaration appearing within the body of a directly enclosing interface is implicitly static and public. Use of the access modifiers, private or protected, is contradictory and results in a compile-time error. In contrast, the modifiers, private and protected, are applicable to a member type declaration appearing within the body of a directly enclosing class. The modifier, final, is never applicable to an interface. The keyword, implements, is not a modifier.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>