File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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!