title: Object Oriented adding items to an a arrayList
body: <p>I'm new to object orientated languages and just have a few questions about adding items to an <code>ArrayList</code>. I've come up with a solution however I'm confused as I've seen another method used which I don't understand. Could someone please explain to me how the second method works?</p>
  <p><strong>I have two classes one for an item in a shop:</strong></p>
  <pre><code>public class Item {
      String name;
      double weight;
      double price;
      
      public Item(String itemName,double itemWeight, double itemPrice){
          this.name = itemName;
          this.weight = itemWeight;
          this.price = itemPrice;
      }
      public String toString(){
          return(name + &quot; has a weight of &quot; + weight + &quot; and a price of &quot; + price);
      }    
  }
  </code></pre>
  <p><strong>And another of an arraylist of items in the shop:</strong></p>
  <pre><code>import java.util.ArrayList;
  public class ItemList{
      String itemName;
      ArrayList&lt;Item&gt; itemList = new ArrayList&lt;&gt;();
       
      public ItemList(String name) {
          itemName = name;
      }
      public void addItem(Item item1){
          itemList.add(item1);
      }
      public void printItems(){
          for(int i=0; i &lt; itemList.size(); i++){
              System.out.println(itemList.get(i));
          }
      }
  }
  </code></pre>
  <p><strong>I then have a main method that adds items to the list then prints them:</strong></p>
  <pre><code>public class ShopMain {
      public static void main (String[] args){
           ItemList myList = new ItemList(&quot;Fruit&quot;);
           Item apple = new Item(&quot;Apple&quot;, 100, 60);
           myList.addItem(apple);
           Item banana = new Item(&quot;Banana&quot;, 118, 50);
           myList.addItem(banana);
           
           myList.printItems();
      }
  }
  </code></pre>
  <p><strong>However the second method I've seen people use doesn't work for me and is formatted like this:</strong></p>
  <pre><code>public class HopefulShopMain{
      public static void main (String[] args){
           ItemList myList = new ItemList(&quot;Fruit&quot;);
           
           myList.addItem(&quot;Apple&quot;, 100, 60);
           myList.addItem(&quot;Banana&quot;, 118, 50);
      }
  }
  </code></pre>