Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes member interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "member interface" Watch "member interface" New topic

member interface

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481

class ppp {
static class StaticNested { interface ABC {}} // 1
class NonStaticInner {interface DEF {}} // 2
interface GHI {} // 3
A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. None of the above

Answer is b as member interface is implicitly static.But I would say option c also will give compile time error.

I verified the java language specification that says

Please clarify my doubt.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
If you remove line 2 from your code it compiles without problems. So option c) is wrong.

If nested interfaces are implicitly static, then it means that line 3 is the same as:

which compiles without problems.

The JLS example is a little misleading. The code

compiles. The interface NeverInner is not an "inner" interface (there is no such thing), it is a "static nested" or "nested" interface.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
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.

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 481
Thankyou very i got the misleading.
I agree. Here's the link:
subject: member interface
It's not a secret anymore!