File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes method inside main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method inside main method" Watch "method inside main method" New topic
Author

method inside main method

Asanga Aux
Greenhorn

Joined: Oct 19, 2009
Posts: 1
Hey,

Why cant we declare a method inside the main method and call it?



why its giving illegal start of expression ?

Thank You.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

inside a main method ,you can declare a method(static) . but you cant define(implement) a method.

Hope this helps
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

and welcome to javaranch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Welcome to JavaRanch.

Because it is simply not possible in Java to define methods inside methods. It's just not part of the language's syntax.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method inside main method
 
Similar Threads
Var-arg doubt
How Many Objects Are Created?
Passing null as a method argument
java
Instance Initialisation/Strange behavour