File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question about instantiating an inner class

 
chang Anne
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 330
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic