java - eclipse acting weird when creating methods -


i don't see wrong here, working on different method had problems tried simplify check mistake ended going simple method , still have same error.

enter image description here

when put mouse on redx @ line 6 message saying:

multiple markers @ line  -syntax error on token "(",;expected   -syntax error on token ")",;expected` 

mouse @ line 7 says:

void method cannot return value 2 quick fixes available change method return type 'int' change 'return;' 

i changed public static void public static int , changed method's modifier error @ line 6 appears everytime. don't see wrong here think i'm making mistake needs simple fix, going crazy? never had particular problem before

the problem declaring method called y within main method. in java, cannot nest method declerations.

you have move outside main method scope or else, declare private inner class hold y method.

in short:

public class gat {     public static void main(string args[]) {         ...     }      int y(int a) {         return + 5;     } } 

or:

public class gat {     public static void main(string args[]) {         class inner {              int y (int a) {                 return + 5;             }         }     } } 

the first approach common, end using second approach, when dealing swing events , other threading aspects.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -