• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

static method not running

 
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 67
Mac Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
else compiler interprete this way : "method returning type is static object/variable"
 
Marshal
Posts: 22457
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
reply
    Bookmark Topic Watch Topic
  • New Topic