File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes outer class name obligatory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "outer class name obligatory" Watch "outer class name obligatory" New topic
Author

outer class name obligatory

Dick Eimers
Ranch Hand

Joined: Apr 15, 2006
Posts: 40
In K&B for SCJP5 on page 642 an is stated that 'From outside the outer class instance code (including static method code within the outer class), the inner class name must include the outer class's name.'

However, this is not correct as the following compiles and runs just fine:


What exactly are the rules regarding 'must include the outer class's name'?


<a href="http://eimers.blogspot.com" target="_blank" rel="nofollow">eimers.blogspot.com</a>
Krishna Bulusu
Ranch Hand

Joined: Jan 27, 2006
Posts: 32
the code is not compiling.....
u can not declare the inner class like....b'coz it is not visible by itself to the outside of the outer class....through outer class only u can create an object of inner class....
plz correct me if i am wrong.
krishna.
S Thiyanesh
Ranch Hand

Joined: Mar 19, 2006
Posts: 142
Inside the class containing the inner class there is no need for the outer class qualifier.(even holds for the static method)
Firas Zuriekat
Ranch Hand

Joined: May 09, 2006
Posts: 144
The K&B quote you mentioned is for static classes only.

So it's for cases similar to:

class InnerClasses {
static class MyInner {
}

public static void main(String[] args) {
/*InnerClasses.*/MyInner inner = new InnerClasses().new MyInner();
InnerClasses.MyInner staticClass= new InnerClasses().new MyInner();
}
}
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
R u sure...
Following code is compiling correctly. I compiled it on j2sdk 1.2.1 and j2sdk 1.5.

On 1.5 it gives runtime exception...
Exception in thread "main" java.lang.UnsupportedClassVersionError: InnerClasses
(Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:403)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:10
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
at java.lang.ClassLoader.loadClass(ClassLoader.java:280)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:275)
at java.lang.ClassLoader.loadClass(ClassLoader.java:237)

.....................................................................

But on 1.2, it compiles and run without any output.

regards


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Firas Zuriekat
Ranch Hand

Joined: May 09, 2006
Posts: 144
Sorry the code that runs with static classes is

public class InnerClasses {
static class MyInner {}

public static void main(String[] args) {

InnerClasses.MyInner staticClass= new InnerClasses.MyInner();
}
}

Again the quote from K&B book is about static classes as this example (above) shows.
Dick Eimers
Ranch Hand

Joined: Apr 15, 2006
Posts: 40
The code I posted in my initial post compiles and runs just fine on Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: outer class name obligatory