Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes top level nested interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "top level nested interfaces" Watch "top level nested interfaces" New topic
Author

top level nested interfaces

sai donthneni
Ranch Hand

Joined: Mar 26, 2006
Posts: 50
since the top level nested interfaces are implicitly static then will the members of the interface are also static?

Can a toplevel nested class can have a non-static member? Since if a class is defined as static then aren't the methods defined in that static class are static?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

First, I think it's worth pointing out that "top level nested" is an old term for static nested. The idea was that if a nested class definition is static, then it's not tied to an instance of the enclosing class, and can therefore be treated as a "top level" class.

But as the JLS now states, "A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class." And "an inner class is a nested class that is not explicitly or implicitly declared static."

So...

since the top level nested interfaces are implicitly static then will the members of the interface are also static?

Interface fields are implicitly static. But interface methods are implicitly abstract, so they cannot be static. This is true whether the interface is nested or not.

Can a toplevel nested class can have a non-static member?

Certainly. As demonstrated below, making the nested class static does not make the members of that class static.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
wood burning stoves
 
subject: top level nested interfaces