File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface is static???

 
RAGU KANNAN
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

For the following question there answer's are "A" and "E". But it looks "B" also correct.The whizlab says wrong because the interface is internally static. I read K&B book says interfaces are internally public and abstract. So I couldn't understand, pls explain to me.

Thanks, Raghu.K

 
Dave Casman
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is, you get a compile error at line 3.



Your voidf method does not have a return type. What was the question?
 
Meena R. Krishnan
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, at line 3 there is a typo, there should be a space between void and f().


As far as the option B, I just compiled it and with B at line 6 and got an error saying

"The member interface J can only be defined inside a top-level class or interface"
 
RAGU KANNAN
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Krishnan, for correcting the "TYPO"

Dave,
My Question is why answer [B] "Interface J{}" is not allowing in Inner class?

Thanks, Raghu.K
 
Meena R. Krishnan
Ranch Hand
Posts: 178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

There is no such thing as an inner interface. Because, interfaces are always implicitly static. They are always top-level, not inner. Inner classes cannot have any static modifiers at all.


from --> http://www.developer.com/java/article.php/859381
 
Aniket Patil
Ranch Hand
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From JLS:

"Inner classes may not declare static members, unless they are compile-time
constant fields" and

"Member interfaces are always implicitly static so they
are never considered to be inner classes."

Interfaces are not implicitly public, unless you declare them to be.
[ September 17, 2006: Message edited by: Aniket Patil ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic