Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.654 :

Posted: Mon Oct 31, 2011 10:05 am
by shkolnik
Option "Objects of top level nested classes can be created without creating instances of their Outer classes." seems to be ambigous. Please consider changing to "Objects of top level static nested classes can be created without creating instances of their Outer classes." Without this qualification I don't think the statement is correct as it is not true for all objects of top level nested classes.

Re: About Question com.enthuware.ets.scjp.v6.2.654 :

Posted: Mon Oct 31, 2011 7:49 pm
by admin
Hello,
You are right. This and a few other questions were based on an outdated terminology. Initially, when Java came out with inner classes, static nested classes were also considered top level classes. To quote, Sun's "Inner Class" specification:
In addition, the programmer can define one top-level class as a static member of another top-level class. Unlike an inner class, a top-level class cannot directly use the instance variables of any other class. The ability to nest classes in this way allows any top-level class to provide a package-like organization for a logically related group of secondary top-level classes.

Inner classes and nested top-level classes are implemented by the compiler, and do not require any changes to the Java Virtual Machine. They do not break source or binary compatibility with existing Java programs.
Later on, they changed the terminology as follows:
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. An inner class is a nested class that is not explicitly or implicitly declared static. A class defined inside an interface is implicitly static.
Sorry for the confusion. This has now been updated.

HTH,
Paul.