Results 1 to 4 of 4
Thread: Calling another method help?
- 11-24-2011, 02:21 AM #1
Member
- Join Date
- Nov 2011
- Location
- birkenhead
- Posts
- 6
- Rep Power
- 0
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.
- 11-24-2011, 02:29 AM #2
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.
-
Re: Calling another method help?
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:
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().Java Code:public void selectHoliday(Holiday holiday) { System.out.println("Member " +membershipNumber+ " has selected a holiday ref number " + holiday.getRefNo() + "."); }
- 11-24-2011, 02:45 AM #4
Member
- Join Date
- Nov 2011
- Location
- birkenhead
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Thread problem, calling method in run method
By majk in forum Threads and SynchronizationReplies: 4Last Post: 09-27-2010, 11:40 AM -
Calling The main method from another method
By SwissR in forum New To JavaReplies: 3Last Post: 07-27-2010, 11:03 AM -
help w/ method calling
By blueduiker in forum New To JavaReplies: 2Last Post: 01-12-2010, 07:55 AM -
calling method from main method
By bob_bee in forum New To JavaReplies: 4Last Post: 10-02-2009, 05:30 PM -
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


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks