Results 1 to 4 of 4
  1. #1
    xxdave is offline Member
    Join Date
    Nov 2011
    Location
    birkenhead
    Posts
    6
    Rep Power
    0

    Default Calling another method help?

    I have a Member Class and Holiday Class

    public void selectHoliday(String Holiday)
    {
    System.out.println("Member " +membershipNumber+ " has selected a holiday ref number " +refNo+ ".");
    }

    My question is how can I link the refNo from my Holiday Class to the Member Class where this piece of code is?

    Thanks.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Calling another method help?

    The Member class needs to have a reference to/instance of the Holiday class. Then you would make a method call on that instance. Just like you call equals/length/charAt etc on a String object.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Calling another method help?

    Quote Originally Posted by xxdave View Post
    I have a Member Class and Holiday Class

    Java Code:
    public void selectHoliday(String Holiday)
    {
       System.out.println("Member " +membershipNumber+ " has selected a holiday ref number " +refNo+ ".");
    }
    My question is how can I link the refNo from my Holiday Class to the Member Class where this piece of code is?
    Your problem (I think) is that you're passing in a String representation of the Holiday in your selectHoliday(...) parameter and so have no way of referencing the Holiday object. Instead, if you have a decent Holiday class, consider changing your method structure so that it accepts a Holiday parameter, not a String parameter. Then you can call methods on the Holiday reference that was passed into the method:

    Java Code:
    public void selectHoliday(Holiday holiday)
    {
       System.out.println("Member " +membershipNumber+ " has selected a holiday ref number " + holiday.getRefNo() +  ".");
    }
    Note that you should not access the actual refNo property (or variable) but instead should call a public accessor method to obtain it, a "getter" method such as getRefNo().

  4. #4
    xxdave is offline Member
    Join Date
    Nov 2011
    Location
    birkenhead
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Thread problem, calling method in run method
    By majk in forum Threads and Synchronization
    Replies: 4
    Last Post: 09-27-2010, 11:40 AM
  2. Calling The main method from another method
    By SwissR in forum New To Java
    Replies: 3
    Last Post: 07-27-2010, 11:03 AM
  3. help w/ method calling
    By blueduiker in forum New To Java
    Replies: 2
    Last Post: 01-12-2010, 07:55 AM
  4. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 05:30 PM
  5. Replies: 29
    Last Post: 09-25-2008, 07:55 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
  •