aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B doubt: Inner class name from static context of outer class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B doubt: Inner class name from static context of outer class" Watch "K&B doubt: Inner class name from static context of outer class" New topic
Author

K&B doubt: Inner class name from static context of outer class

Sasha Ruehmkorf
Ranch Hand

Joined: Mar 29, 2007
Posts: 115
K&B wrote at the top of page 642:

From outside the outer class instance code (including static method code within the outer class), the inner class name must now include the outer class's name:

MyOuter.MyInner


I've tried and it seems to work fine even without the outer class's name, for instance:


Is this a new feature from Java 6, a characteristic from my compiler or has it always been that way?
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707

From outside the outer class instance code (including static method code within the outer class), the inner class name must now include the outer class's name:
MyOuter.MyInner




Case #1: Even if the Nested is nested (static inner class), outside the
enclosing class you must refer to it using Outer class name; Nested does not
stand individually.

Case #2 In case of inner class (non nested or non static inner class),
you must have reference to the outer class to create an instance of the
inner class.

Case #3 It is not special, you have created an instance of the outer class
first and in the next line used that reference to create the inner class.


Thus we see that from outside the outer class instance code(including static
method code within the outer class), the inner class name must now include
the outer class's name. K&B

Thanks,


cmbhatt
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
Originally posted by Sasha Ruehmkorf:

From outside the outer class instance code (including static method code within the outer class), ____big_space_here___ the inner class name must now include the outer class's name:

MyOuter.MyInner

means:
outside outer class non-static code && outside outer class static code

the "(including ..." part is related to first part of sentence

However, I read it first time probably as you did. There should be bigger space :-).

[ May 10, 2007: Message edited by: John Stone ]
[ May 10, 2007: Message edited by: John Stone ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B doubt: Inner class name from static context of outer class