This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to access inner class members of class Ten which is implemented inside construcor of class Two? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to access inner class members of class Ten which is implemented inside construcor of class Two?" Watch "How to access inner class members of class Ten which is implemented inside construcor of class Two?" New topic
Author

How to access inner class members of class Ten which is implemented inside construcor of class Two?

Sanjay Kumar Sah
Greenhorn

Joined: Nov 12, 2009
Posts: 3
public class One {
final Integer y = 10;

class Two //Class Two starts here
{
final int x;
public Two() //Constructor starts here
{
x = 10;

class Ten // Class Ten starts here
{
int x = 11;
} // Class Ten ends here

}// Constructor ends here
} //Class Two ends here
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3087
    
    5

Hi Sanjay, I moved your topic to the Java In General forum because I think it is more appropriate here, rather than in IDEs...


Steve
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3087
    
    5

You can do so inside the Two constructor by creating a new instance of Ten, then accessing the value you want. Example:


Note that you can only do so inside the Two constructor. Since the class was defined inside the constructor then it only has scope inside that method. So as shown in the above code sample you can't use or refer to Ten even inside another method of the same class.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32827
    
    4
Surely that local class will go out of scope when the constructor completes?
Sanjay Kumar Sah
Greenhorn

Joined: Nov 12, 2009
Posts: 3
Thanks...,It really works.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access inner class members of class Ten which is implemented inside construcor of class Two?
 
Similar Threads
can final variables instantiated after they declare
Doubt in Static initialization
How deep can you nest inner classes, and how do you go about initializing the inner most class
final modifier in variable
inner class question