• 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

Calling Methods Help

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so basically i have to call the returnRatio method in my main class...and I have no idea how to call it because im not creating an object and then calling the method on the object. here is my code of the method...


EDIT by mw: Added Code Tags to original poster's indentation.

[ February 11, 2007: Message edited by: marc weber ]
[ February 11, 2007: Message edited by: Bear Bibeault ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To run this as a program, you need a "public static void main(String[] argv) method. In that method, you can create an instance of this class and call the method.
 
Jason Mackie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what would the syntax be tho? i have 2 classes...1 called ratio which holds the code above, and the other is called ratioTester which holds the public static void method...what would i put in ratioTester?
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ernest has pretty much laid out the answer for you. You're asking for the actual syntax without showing that you have at least tried. You'll find that if you show some effort, people around here will be more willing to assist you.

Now Ernest said that in the main method (which will be in your RatioTester class) you need to create an instance of the Ratio class and then you will be able to call your method.

So you need to know three basic things here:
1) how do you create an object from a class (hint you need a java key word)
2) how to assign a reference to that object, and
3) how to call a method on the object.

These are all basic things that can be found in any beginner's Java text, or alternatively you can search for on the Web or on this site. There is plenty of material out there.

Good luck!

Regards,
JD
 
Jason Mackie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok so I tried that and it wasnt working last night so thats why I asked the "stupid" question lol...but i realized i forgot the public static void main (String[] args) statement...thanks for your help guys
 
Are we home yet? Wait, did we forget the tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic