• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling Methods Help

 
Jason Mackie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic