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 Instantiating Local Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Instantiating Local Classes" Watch "Instantiating Local Classes" New topic
Author

Instantiating Local Classes

Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24


The above code is from a book. I'm unable to understand what the author means by " In the non-static method, the reference to the instance of the enclosing context is passed implicitly in the constructor call of the non-static local class at (6). "
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Inner Story (<= click) .

download a good decompiler (for example jad) , and open the inner classes. surprisingly you can find a different default constructor !
Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
Seetharaman I looove campfire stories Liked the Pass-by-value Please story

Thanks for sharing the link and for your response

Downloaded JD-GIU (a java decompiler) and decompiled the following code :


FOUND THIS :



Now my question is - is there some specification about how class files would be named once we define inner classes - like it shows $ as a seperator; and $1 as a seperator for local classes?
Mala Gupta
Author
Ranch Hand

Joined: Sep 27, 2002
Posts: 245
    
    9
Vishnu,

Now my question is - is there some specification about how class files would be named once we define inner classes - like it shows $ as a seperator; and $1 as a seperator for local classes?


$ followed by an integer is used for local classes because you can declare multiple local classes with the same name, in different methods. The following code adds a definition of local class 'InsideMethod' in 'method2()':



When you compile the above class, the Java compiler will generate the following class files for the local inner classes 'InsideMethod' defined in 'method()' and 'method2()':

Outer$1InsideMethod.class
Outer$2InsideMethod.class

With respect,
Mala


Author of Manning's OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
Thanks for your response Mala
Abdullah mohammad
Greenhorn

Joined: Feb 22, 2013
Posts: 3
Seetharaman Venkatasamy wrote:Inner Story (<= click) .

download a good decompiler (for example jad) , and open the inner classes. surprisingly you can find a different default constructor !
Vishnu Khera
Greenhorn

Joined: Nov 29, 2008
Posts: 24
 
Consider Paul's rocket mass heater.
 
subject: Instantiating Local Classes
 
Similar Threads
instanize interface?
which draw() is called?
anonymous class giving compile time error
Constructors and Polymorphism
Can any one please explain this