Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Illegal start of expression" in "private"

Tags:

java

private

I'd like to know how I could fix the illegal start of expression error on line 3

1 public class Example {
2     public static void main(String[] args) {
3         private int n;
4     }
5 }

Thanks!

like image 980
pabombs Avatar asked Dec 01 '13 00:12

pabombs


2 Answers

Declarations with scope (i.e. private, protected, or public) must be outside your functions, including the main() one. Move these declarations to the class level to fix this syntax error.

like image 135
Sergey Kalinichenko Avatar answered Nov 14 '22 21:11

Sergey Kalinichenko


The private is being used in the body of a method. It can not be used there. It can be used in the body of a class ... outside the method.

like image 29
AgilePro Avatar answered Nov 14 '22 21:11

AgilePro