Results 1 to 3 of 3
  1. #1
    TMobotron is offline Member
    Join Date
    Sep 2010
    Rep Power

    Default 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.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Destiny Islands
    Rep Power


    To make a static call, it's simply className.nameOfStaticMethod(parameters);.

    More on that (if interested): Java: Static/Class methods

  3. #3
    TMobotron is offline Member
    Join Date
    Sep 2010
    Rep Power


    Thanks for the response, that's what I thought I had to do but when I try that I get this error:

    " cannot find symbol
    symbol : variable BankAccountParser
    location: class Assignment

    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

  1. How to know which class is calling a method?
    By ranju4u6 in forum New To Java
    Replies: 14
    Last Post: 09-16-2010, 08:41 AM
  2. Child-Class Calling a Method in a Parent-Class
    By Blah_ in forum New To Java
    Replies: 5
    Last Post: 09-29-2009, 02:48 AM
  3. Replies: 29
    Last Post: 09-25-2008, 07:55 PM
  4. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM
  5. Calling method from another class
    By asahli in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 06:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts