Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java" Watch "java" New topic
Author

java

sailaja cherukuri
Greenhorn

Joined: May 02, 2013
Posts: 9
hiii hiii i am getting these errors ..how to avoid these errors

class Method
{
public static void main(String args[])
{
static int methods()
{
int amount=10000;
return amount;
}
System.out.println(" it returns 10000");
}
}

hiii i am getting these errorss......... but i am not getting why
these errors camee... i think every thing is correct but ...

Method.java:5: error:illegal start of expression
static int methods()

Method.java:5: error: ';' expected
static int methods()
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Welcome to the ranch Sailaja. Please use code tags when referring to code:



Looks much better now.


~ Mansukh
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

The compiler is complaining because you are trying to nest the method called methods() inside the main() method , which is not allowed in Java language. Nested classes are allowed though, but that's a different concept.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java