Results 1 to 3 of 3
- 09-17-2010, 05:54 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 2
- Rep Power
- 0
Calling a method in a utility class
Hey guys, total java noob here. I'm having some real trouble getting this homework assignment done here.
I have multiple classes, Assignment holds my main method, BankAccount is the parent class of Saving, MoneyMarket, and Checking. BankAccountParser is a class in a separate file, and the description I am given is this:
The BankAccountParser class is a utility class that will be used to create a bank account object (one of a saving object, a checking object, and a money market object) from a parsable string. The BankAccountParser class object will not be instantiated. It must have the following method:
public static BankAccount parseStringToAccount(String lineToParse)
Now, I think I know how to set up the method just fine, but I'm unsure of how I call the method from my main method. I know if I had an object of the class named b it would be b.parseStringToAccount(....), correct? But how can I call the method without instantiating a BankAccountParser class object? Thanks in advance.
- 09-17-2010, 06:28 AM #2
To make a static call, it's simply className.nameOfStaticMethod(parameters);.
More on that (if interested): Java: Static/Class methods
- 09-17-2010, 06:39 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 2
- Rep Power
- 0
Thanks for the response, that's what I thought I had to do but when I try that I get this error:
"
Assignment.java:55: cannot find symbol
symbol : variable BankAccountParser
location: class Assignment
BankAccountParser.parseStringToAccount(inputInfo);
^
"
BankAccountParser is the name of my class, parseStringToAccount(String lineToParse) is my method.
EDIT: This may be a classpath problem, I'm looking into that now but if there's something else it might be in the mean time please let me know. I've been trying to figure this out for hours.
EDIT2: Ugh. That was it. I wasted so much time trying to solve this. Can't thank you enough for the help though Zack.Last edited by TMobotron; 09-17-2010 at 06:45 AM.
Similar Threads
-
How to know which class is calling a method?
By ranju4u6 in forum New To JavaReplies: 14Last Post: 09-16-2010, 08:41 AM -
Child-Class Calling a Method in a Parent-Class
By Blah_ in forum New To JavaReplies: 5Last Post: 09-29-2009, 02:48 AM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 07:55 PM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM -
Calling method from another class
By asahli in forum New To JavaReplies: 1Last Post: 12-15-2007, 06:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks