title: Java arraylist of different object class
body: <p>i have an issue with the understanding the arraylist which contain the objects from different classes. I have 6 objects. All of objects have 2 attributes in common.(ID,Type)
  Every object has its own attributes. I created mainObject class with 2 atr (ID,Type). The other objects extends the mainObject so they have </p>
  
  <pre><code>class mainClass{
      this.id=id;
      this.type=type;
  }
  class extendedClass extends mainClass{
      super(ID,Type);
      this.atr1=atr1;
  }
  
  class extendedClass2 extends mainClass{
      super(ID,type);
      this.atr2=atr2;
      this.atr3=atr3;
  }
  </code></pre>
  
  <p>I read the informations from file.</p>
  
  <pre><code>FileInputStream fstream = new FileInputStream("data.txt");
  // Get the object of DataInputStream
  DataInputStream in = new DataInputStream(fstream);
  BufferedReader br = new BufferedReader(new InputStreamReader(in));
  String strLine;
  // Read File Line By Line
  while ((strLine = br.readLine()) != null) {
      // Print the content on the console
      String s[] = strLine.split("\\|");
      mainClass myObj = new mainClass(s[0], s[1]);
  
  ArrayList&lt;mainClass&gt; items = new ArrayList&lt;mainClass&gt;();
  items.add(myObj);
  </code></pre>
  
  <p>I need all objects to be readed from file line by line and store them in the array list.
  How should i do this? I tried the <code>ArrayList&lt;Object&gt; list = new ArrayList&lt;Object&gt;</code>, but its not working. The point is read all the objects from file, sort them due to chosen attribute(id,type).</p>