This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a question about instantiating an inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a question about instantiating an inner class" Watch "a question about instantiating an inner class" New topic
Author

a question about instantiating an inner class

chang Anne
Greenhorn

Joined: Jul 02, 2003
Posts: 29
Hello,
I read the K&B book on page 462, it said
"From outside the outer class instance code
(including static method code within the outer class), the inner name must include the outer class name"
But I run the following code without Error
I don't get the stentence "(including static method code within the outer class), the inner name must include the outer class name"
class Outer{
private int size = 5;

class Inner {

void doStuff(){

System.out.println(size);
}

}

public static void main( String args[] ) {

Inner i = new Outer().new Inner();

i.doStuff();

}

}
dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330



You can use this syntax within the outer class. But you cannot use this outside the outer class (from another class). You must use
"(including static method code within the outer class)"

is a static method code within the outer class.
the inner name must include the outer class name

I think its good practice to always include the outer class name so regardless if you're inside or outside the outer class your code will work.


SCJP 1.4<br />SCWCD 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a question about instantiating an inner class
 
Similar Threads
K&B doubt: Inner class name from static context of outer class
What's the result of this inner class code?
outer class name obligatory
Bug in K& B?
inner class instantiation from outside the the outer class