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

Nested Interface Declarations within Interfaces

 
Zak Nixon
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
naren babu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Dan's reasoning
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic