wood burning stoves
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Methods within Methods?" Watch "Methods within Methods?" New topic

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. :-)

SCJP for the Java� 2 Platform

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?
[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?
It's not a secret anymore!