aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Class inside method 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 "Class inside method" Watch "Class inside method" New topic
Author

Class inside method

Aparna Narayanan
Ranch Hand

Joined: Nov 07, 2000
Posts: 44
Hi,
If I declare and define a class inside a method, I can access only the final local variables of the method, isn't it? The reason given in RHE for this is that the object of the class declared inside method should be able to outlive the method and this is possible only if variables that can be accessed from the method are final. But then, I am not able to create/access an object of the class declared inside the method outside the method at all!!! Then, what's the big deal in allowing only final variables of the method to be able to be accessed??? Or is there any way that I can create/access an object of the class declared inside a method outside the method??
Thanks,
Aparna
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

that is a good question. that went through my mind before too. all i know right now is a local class can only have "friendly" access. im fairly sure of this.


SCJP
Visit my download page
Aparna Narayanan
Ranch Hand

Joined: Nov 07, 2000
Posts: 44
Hi Randall,
Thanks for ur reply. But then, such a thing is not discussed even in JLS, where else to look for answers? Everywhere, the examples comfortably declare an object inside the method itself. There has been no example/ no mention of how that object can be accessed outside. Any help from anyone would be well appreciated.
Thanks,
Aparna
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class inside method