Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting ; expected error for the below program..

 
Janardhan Mudduluru
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mates,

I am a beginner...getting ; expected error for the below program..

solution will be much appreciated..

Thanks
Janardhan M
 
Henry Wong
author
Marshal
Pie
Posts: 21506
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can't just declare a method anywhere. In this case, you are trying to declare the hi() method inside the main() method. This is not legal.

Henry
 
salvin francis
Bartender
Posts: 1309
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
let me modify your example so that it works...



There you go...

what you should learn:
1. methods are not functions, so you cant have:

you are permitted:


2. methods are not functions , so you cant have



you are permitted:


 
Av Vinay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.,

public class Example {

public Example() {
}
public static void main(String[] args){
String c = hi();
System.out.print(c);
}
public static String hi()
{
return "Hi";
}
}

As explained in the last reply., You just can't write the metod definintion anywhere you want. The other solution for your problem is to write a static function which can be directly called by the static function main() as shown above.

Regards.,

 
Campbell Ritchie
Sheriff
Pie
Posts: 50246
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is hard to read if you don't use the Code button.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic