• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help me with this minor mistake

 
Greenhorn
Posts: 23
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone, i am novice here))))



the thing is that Eclipse gives me a mistake in theAverage method - it underlines long[] y - i don't know why!
"syntax error misplaced constructs"

any suggestions?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am assuming that it is at line 16? When you call a method, you don't need to declare the type of the variable that you are passing -- the compiler knows what it is.

Henry
 
kambar bek
Greenhorn
Posts: 23
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Henry!
it works ok now.

i also have one more question

why should i declare the method theAverage static?

it looks like all methods outside of static main method

must be declared static ? right?
can you explain it to me?
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not declare your method static unless you are invoking it directly in a static context.
If you want to invoke it directly in main method (a static method), you must declare it as static

Look at the following use:



In the snippet of code your method theAverge has to be static, because i am invoking it inside a static method (the main method) directly.

But look at this:


now you create an object of class Operations_with_Array and you invoke the method theAverage on that object.
The method now is an instance method, not a static method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic