wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 371


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: 371
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: 19655
    
  18

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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static method not running
 
Similar Threads
need help with compareTo()
Java problems, accumulating totals
Depth first search recursive, problem on graph[picture + code]
Looping a switch statement?
User Defined Package Doubts