This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Methods within Methods? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Methods within Methods?" Watch "Methods within Methods?" New topic
Author

Methods within Methods?

Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
Is it OK to have a method(s) within a method? An example would be to have a method called fn within main all within a class. Is this OK to do?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes, if that method is within a class that's within a method. In this case the method will belong to the "inner class" that's within the outher method. I hope I said that right. :-)


------------------
Bosun
SCJP for the Java� 2 Platform


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
You could call a method from within a method as long as the calling method can actually see the method it is calling (static vs. instance)
You cannot do something like this though:

The only thing close to that is what Bosum suggested, putting an inner class within the method. That inner class would contain a method itself, but it would be within the scope of the class, and not really the method the class was built in.
Clear as mud?
Jason
[This message has been edited by jason adam (edited November 13, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Methods within Methods?
 
Similar Threads
Nesting a method within a method
NX: Help with storing DB size
methods will execute?
main and other methods in same file?
sorry ... i know you guys have seen this one many times ...