This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes getClass() from another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getClass() from another class" Watch "getClass() from another class" New topic
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: 18507
    
  40



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: 37926
    
  22
ollie monch wrote:Any clues on how to do this?
Read Henry Wong's post on this thread.
 
wood burning stoves
 
subject: getClass() from another class
 
Similar Threads
Instantiating an enum
not getting what this servlet is doing+MVC
Problem with abstract methods
adding objects to a vector
How to pass request Attribute to Action in Struts 2