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 How the inner class are instantiated ? 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 "How the inner class are instantiated ?" Watch "How the inner class are instantiated ?" New topic
Author

How the inner class are instantiated ?

dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90





class B is the inner class of Class A

I want to instantiate the class B in the Class test

which means

i have to use dot operator as

outerClass.innerClass refVar = new outerClass.innerClass();

Its fine for one inner class

But what about if there is one more innerclass in B as


Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

To create a non-static inner class Object you need an instance of the enclosing class. Like this:


With more classes then it just builds up:

But I don't think that you'll ever need such a construction.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
I think if the inner class is static i.e

if class B is static ?

even though it doesnt matter the

A.B ab = new A().new B()

Am i correct ?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

If B is static then you can't instantiate it with:

But with:


But haven't you tried it? You'll learn much more.
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
i had tried .

But i was not sure about instantiation related to static .

Thank you for clearing my doubt.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How the inner class are instantiated ?