Jump to content

Java - Multiple toString methods


aeonsky

Recommended Posts

How do I make this simple example work, with multiple toString methods.

 

In class A, you instantiate class B, and print a B object using B's toString method. However, the B object contains multiple instantiated class C objects. Class C has its own toString method.

 

Here's what I did, in class B I just System.out.print() all class C objects (thus using C's toString method) and returned "" at the end of B's toString method. Is there a better way to do it?

Link to comment
https://forums.phpfreaks.com/topic/175038-java-multiple-tostring-methods/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.