• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static method not running

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When I try to compile this code, I am getting following output.
LargeNum.java:33: <identifier> expected
void static stGo() {
^
LargeNum.java:33: '(' expected
void static stGo() {
^
LargeNum.java:33: invalid method declaration; return type required
void static stGo() {
^
3 errors


1) Why is this static method not working ?

2) Can I declare static variable inside main() ? Its not working here.

Thanks
 
Dhruva Mistry
Ranch Hand
Posts: 67
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nirjari,

Your code for static method is


which doesnt fulfil the syntax of a java method it should be like,

<access&non-access modifiers> <return-type> <method-name>

which can be fulfilled by putting the return type : "void" right before the method name. like,



and, public n static - access modifier/control
void - return type of a method
 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, so order is also important. I thought, if you change the order , it will not be a problem.

Thanks
 
Dhruva Mistry
Ranch Hand
Posts: 67
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
else compiler interprete this way : "method returning type is static object/variable"
 
Rob Spoor
Sheriff
Pie
Posts: 20744
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nirjari patel wrote:Oh, so order is also important. I thought, if you change the order , it will not be a problem.

Thanks

Order is not important, except for a few. As said, the return type must come immediately before the method name. The method-generic type*, if present, must come immediately before the return type. Before that, any modifiers (public/private/protected, synchronized, static, etc) can come in any order.

* If you don't know what it means, don't worry. If you're still interested look up how generics in Java work.
 
Adam Richards
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The original post seems to have been edited to remove syntax errors. However, the stGo() method will still not execute, because it's never called from anywhere (at least, not in the code shown).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic