| Author |
getClass() from another class
|
Matthew Peters
Greenhorn
Joined: Jul 10, 2009
Posts: 2
|
|
Hi all. Great to see a greenhorn friendly java site! So many forums seem to neglect the beginners...
Anyway, my problem is this:
- I need to return Customer from Bank where Customer is another class
- I then need to access a toString() method within Customer (eg Bank.getCustomer().toString();)
public class Bank
{
...
public Customer getCustomer()
{
return ???;
}
...
}
public class Customer
{
...
public String toString()
{
...
return sbuilder.toString();
}
}
Any help would be much appreciated! Cheers. Ollie
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Well, that is completely up to you -- it's your application. Are you returning a favorite customer? Are you returning the last customer that came into the bank? Are you returning the customer based on a transaction? or a session that the caller is holding? etc. It's purely an implementation detail.
Now, of course, you can also do this.
But I highly doubt you want that... Banks shouldn't be able to just create a customer, so it won't make sense for your program to do that...
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Matthew Peters
Greenhorn
Joined: Jul 10, 2009
Posts: 2
|
|
I actually just want to return the customer (this is a very simple model at this stage)... doesn't have to be a favorite or last customer...
Any clues on how to do this?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
ollie monch wrote:Any clues on how to do this?
Read Henry Wong's post on this thread.
|
 |
 |
|
|
subject: getClass() from another class
|
|
|