aeonsky Posted September 21, 2009 Share Posted September 21, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/175038-java-multiple-tostring-methods/ Share on other sites More sharing options...
aeonsky Posted September 22, 2009 Author Share Posted September 22, 2009 Please disregard my question. I forgot I can use toString on each object and store it in a string. In class B's toString, I can just return that string. Quote Link to comment https://forums.phpfreaks.com/topic/175038-java-multiple-tostring-methods/#findComment-922638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.