An instance of a top level nested class can be created without an instance of its enclosing class.
I think what they are referring to here is the static nested class. But the problem is that the term top level nested class does not exists in the JLS. There is a term top level class but it refers to any class that is not nested. Any comments?
Exactly Alton! The term "top level nested class" refers to a static inner class, and the book on Java Certification by Khalid Moghul also uses the same to explain the concept of different types of nested/inner classes. If I may quote from the book
A top level nested class or interface is similar to a top level or interface, but it is defined as a static member of an enclosing top level class or interface (Section 7.2)
The term is used because the behaviour of static inner classes is hardly any different from the normal top level classes.
Joined: May 30, 2003
Hi Anupreet, Thank you for your reply. I guess the main issue is that the term "top level nested class" does not exists in the JLS. They should not be using terminologies from one particular book because different authors may use different terminologies. [ August 19, 2003: Message edited by: Alton Hernandez ]
Joined: Jun 17, 2003
Yes, U r right Fren! In the JLS, second line of the chapter 8 is
"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".
So if "a top level class is a class that is not a nested class" then term "top level nested class" is a kind of oxymoron!! Maybe it is used more to relate to the behaviour of a specific type of nested classes, than as a technically correct reference. So clearly, such usage in exams, mock or real, should be checked. Regards, Anupreet