title: How to get value of toString methods from subclasses into another class, and iterate them through for-loop to add the value into one string?
body: <p>So I've got 4 subclasses which extend DessertItem Class with toString() methods:</p>
  <pre><code>//candy
  
       public String toString() {
           String line1 = String.format(&quot;%-25s$%&quot;,super.getName());
           String line2Pt1 = String.format(&quot;%-16.2flbs%@-8.2/f.:%&quot;, candyWeight, pricePerPound);
           String line2Pt2 = String.format(&quot;%-6f&quot;, calculateCost());
           String line2Pt3 = String.format(&quot;[Tax: $%.-4f]&quot;, super.calculateTax());
           String outputVar = String.format(&quot;%s\n\t%-45s%s%17s&quot;, line1, line2Pt1, line2Pt2, line2Pt3);
           return outputVar;
       }
  
  //cookie
       public String toString() {
           String line1 = String.format(&quot;%-25s$%&quot;,super.getName());
           String line2Pt1 = String.format(&quot;%-16.2flbs%@-8.2/f.:%&quot;, cookieQty, pricePerDozen);
           String line2Pt2 = String.format(&quot;%-6f&quot;, calculateCost());
           String line2Pt3 = String.format(&quot;[Tax: $%.-4f]&quot;, super.calculateTax());
           String outputVar = String.format(&quot;%s\n\t%-45s%s%17s&quot;, line1, line2Pt1, line2Pt2, line2Pt3);
           return outputVar;
       }
  
  //icecream
      public String toString() {
           String line1 = String.format(&quot;%-25s$%&quot;,super.getName());
           String line2Pt1 = String.format(&quot;%-16.2dscoops%@-8.2/f.:%&quot;, scoopCount, pricePerScoop);
           String line2Pt2 = String.format(&quot;%-6f&quot;, calculateCost());
           String line2Pt3 = String.format(&quot;[Tax: $%.-4f]&quot;, super.calculateTax());
           String outputVar = String.format(&quot;%s\n\t%-45s%s%17s&quot;, line1, line2Pt1, line2Pt2, line2Pt3);
           return outputVar;
          }
  
  //Sundae class which extends IceCream class
       public String toString() {
           String line1 = String.format(&quot;%-25s$%&quot;,super.getName());
           String line2Pt1 = String.format(&quot;%-16.2sTopping: %@-8.2/f.:%&quot;, toppingName, toppingPrice);
           String line2Pt2 = String.format(&quot;%-6f&quot;, calculateCost());
           String line2Pt3 = String.format(&quot;[Tax: $%.-4f]&quot;, super.calculateTax());
           String outputVar = String.format(&quot;%s\n\t%-45s%s%17s&quot;, line1, line2Pt1, line2Pt2, line2Pt3);
           return outputVar;
       }
  </code></pre>
  <p>Also, I have got another class - Order, in which I would like to get toString() method values:</p>
  <pre><code> public String toString() {
       String finalOutput = &quot;&quot;;
       finalOutput += &quot;------------------------Receipt-------------------&quot;;
  
       for() {
       
  </code></pre>
  <p>So, my question is How do I access the toString values from sublasses, and then how do I ittereate through them, so I can add the value into my finalOutput variable?</p>