This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes method definition inside main... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method definition inside main..." Watch "method definition inside main..." New topic

method definition inside main...

Sumesh Kumar T N

Joined: Jan 26, 2005
Posts: 10
is it possible to define another method inside main???.....a friend of mine said that we could define "procedures"(???) inside a bit confused...i am sorry if it is stupid...but lemme have a reply pleez
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
There can be a class inside other class called nested class but you cant have a method inside another method.

A suggestion, the best way to figure out issues like this is to write a simple code and compile it then you can learn lot .

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Abhinav Anand
Ranch Hand

Joined: May 02, 2002
Posts: 113

I think your friend was talking about anonymous classes which can be declared and executed inside a method (no matter if it is done in main() method). Code snippet is given below:

Hope this clears the doubt.
I agree. Here's the link:
subject: method definition inside main...
It's not a secret anymore!