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 a question about instantiating an inner 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 "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