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
posted
0
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.
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.