• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling array in main  RSS feed

 
Taylor Hall
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i have the majority of this program finished, but im not sure of one thing



How would i call the above method in main? when i try " theAges.displayAges(ages) ", it doesnt work. What am i missing?
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main method is a static method. The displayAges() method is not. Calling displayAges() from main directly would indeed "not work" insomuch as it would cause a compilation error.
You'd either need an instance of the enclosing class on which to invoke the displayAges method, or alternatively you could declare displayAges() as static, but I'd recommend against that.
 
Carey Brown
Saloon Keeper
Posts: 3327
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taylor Hall wrote:so i have the majority of this program finished, but im not sure of one thing



How would i call the above method in main? when i try " theAges.displayAges(ages) ", it doesnt work. What am i missing?

Method needs to be declared as "public static void".

Also, you are passing in "ages" but using "anArray". Should be using "ages".
 
fred rosenberger
lowercase baba
Bartender
Posts: 12564
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taylor Hall wrote:? when i try " theAges.displayAges(ages) ", it doesnt work.


I'd start by reading this
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!