wood burning stoves 2.0
The moose likes Beginning Java and the fly likes Calling Methods Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling Methods Help" Watch "Calling Methods Help" New topic

Calling Methods Help

Jason Mackie

Joined: Feb 07, 2007
Posts: 17
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

Joined: Jul 08, 2003
Posts: 24199

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.

[Jess in Action][AskingGoodQuestions]
Jason Mackie

Joined: Feb 07, 2007
Posts: 17
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

Joined: Apr 08, 2004
Posts: 130
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!

Jason Mackie

Joined: Feb 07, 2007
Posts: 17
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
I agree. Here's the link: http://aspose.com/file-tools
subject: Calling Methods Help
It's not a secret anymore!