Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

top level nested interfaces

 
sai donthneni
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic