Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Methods within Methods?

 
Gary Farms
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic