title: Java LinkedList Object inheritance overriden
body: <p>I'm fairly new to Java, I have a linkedList of class ObjectType, I have various subclasses of ObjectType being added to the linkedList, when I pull the object out I am forced to pass it a type of ObjectType and seem to lose the inherited properties of the subclass.... Can anyone shed some light on this for me?</p>
  
  <pre><code>//LIST STORING OBJECT
  public class MyObjectList{
  
      private LinkedList&lt;ObjectType&gt; queue = new LinkedList&lt;ObjectType&gt;();
  
      public MyObjectList()
      {
          queue = new LinkedList&lt;ObjectType&gt;();
      }
  
      public ObjectType addObject(ObjectType myObject)
      {
          queue.add(myObject);
          return myObject;
      }
  
  }
  
  //MY BASIC OBJECT
  public abstract class ObjectType {
  
      public int objectWidth;
  
      public ObjectType () {}
  }
  
  //MY EXTENDED OBJECT BOX
  public abstract class Box extends ObjectType {
  
      public int objectWidth = 50;
  
      public ObjectType () {}
  }
  
  //MY EXTENDED OBJECT PLATE
  public abstract class Box extends ObjectType {
  
      public int objectWidth = 25;
  
      public Box() {}
  }
  </code></pre>
  
  <p>// OK so now if I add a load of boxes to my list of boxes will have their objectWidth set to zero!</p>
  
  <pre><code>mList = new MyObjectList;
  
  for (int i=0;i&lt;10;i++)
  {
     mObject = mList.addObject( new Box );
  }
  </code></pre>
  
  <p>It's important to remember that my list is supposed to be made up of different object types eventually so the baseObject needs to remain as it is. if possible!</p>