Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

How do I call a class from method enclosing class

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 . . .
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Peter and Greg.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic