aspose file tools*
The moose likes Beginning Java and the fly likes static method not running Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static method not running" Watch "static method not running" New topic
Author

static method not running

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 374


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

Joined: Nov 21, 2008
Posts: 67

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

Dhruva
nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 374
Oh, so order is also important. I thought, if you change the order , it will not be a problem.

Thanks
Dhruva Mistry
Ranch Hand

Joined: Nov 21, 2008
Posts: 67

else compiler interprete this way : "method returning type is static object/variable"
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Adam Richards
Ranch Hand

Joined: Nov 03, 2005
Posts: 135
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).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: static method not running