• Post Reply Bookmark Topic Watch Topic
  • New Topic

member interface

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
wise owen
Ranch Hand
Posts: 2023
  • 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.

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou very much.now i got the misleading.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!