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 inside main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method inside main method" Watch "method inside main method" New topic

method inside main method

Asanga Aux

Joined: Oct 19, 2009
Posts: 1

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: 14074

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:
subject: method inside main method
Similar Threads
Var-arg doubt
How Many Objects Are Created?
Instance Initialisation/Strange behavour
Passing null as a method argument