• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getClass() from another class

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Matthew Peters
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ollie monch wrote:Any clues on how to do this?

Read Henry Wong's post on this thread.
 
Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic