This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft 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 Java 8 in Action this week in the Java 8 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: 1506
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
NX: Help with storing DB size
Nesting a method within a method
methods will execute?
sorry ... i know you guys have seen this one many times ...
main and other methods in same file?