Forums Register Login

Q from javacertificate

+Pie Number of slices to send: Send
This statement is marked true in their mock exam:


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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
I wonder if the term top-level nested was used in the first edition of the JLS.
The City calls upon her steadfast protectors. Now for a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 486 times.
Similar Threads
question regarding modifiers applicable to top level class
top level nested interfaces
Why do we need static nested class?
INNER CLASS - Is it an error / JLS
Top level nested classes?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:43:25.