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

How do I call a class from method enclosing class

 
Bala Raj
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How do I call member inner class (inside a method) from outside?

Thanx in advance.
Bala.

[This message has been edited by Cindy Glass (edited September 28, 2001).]
 
greg philpott
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you must call bMethod() in you main() method some hacking needs to be done:
You can achieve this by making your local inner class implement an interface or inherit from some 'normal' class.
This is your example modified to show how this is done:
 
Bala Raj
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi greg philpott,
Thanks for your reply.
Under what condition we have to write a class inside a method?
Can you give some practical examples? What are the advantageous?
Thanks,
Bala.
 
greg philpott
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know of any conditions where a local inner class must be used (a class in a method).
I have never had to use one to solve a problem yet, maybe someone with more Swing or AWT experience might have an example for you . . .
 
Peter Tran
Bartender
Posts: 783
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bala/greg,
You can use a local inner class if the information you want to the class to represent stays within the method and you don't need it once the method returns.
For example, if I have a method that processes records from a database table containing contact information, and this information won't be needed anywhere else, I can create a local inner class to make holding and sorting the records easier.
-Peter
 
Bala Raj
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter and Greg.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic