• 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

inner classes and nested classes

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody suggest an on-line (free) tutorial that most comprehensively covers static and non-static inner/neted classes. Most material I have just cover instantiation and use of these - I have been pretty stumped when attending technical interviews with questions concerning what member variable are accessible from the inner/outer class and the like. I have actually used inner classes in the past, I understand the reasoning for their use, but I (being a bit lazy and a bit of a compiler junkie) usually rely on the IDE pre-compiler sorting this stuff out for me - bit like most of the questions in the Java Programmer exam.
 
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
Hi Phil,

Welcome to JavaRanch!

I would start with the JavaRanch article, Getting in touch with your inner class.

Then for more detailed information, see the inner class chapter from Bruce Eckel's Thinking in Java.
 
Phil Andrews
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, thats a big help - especially the Bruce Eckel article.
 
marc weber
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
I would just point out that Ecklel's use of the term "nested class" is a little misleading, because he gives the impression that a nested class is always static (in constrast to an "inner class").

But according to the JLS, a "nested class is any class whose declaration occurs within the body of another class or interface." And an "inner class is a nested class that is not explicitly or implicitly declared static."

In other words, rather than being mutually exclusive (static vs. non-static), inner classes are actually a subset of nested classes.

Ref:
http://java.sun.com/docs/books/jls/third_edition/html/classes.html
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic