• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

top level nested interfaces

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic