title: Passing a subclass to a method with an abstract class parameter
body: <p>I've been trying to understand what is happening with this example, but haven't been able to so far. Can anyone help?</p>
  
  <p>Say I have these two Abstract classes: </p>
  
  <pre><code>public abstract class AbstractBook&lt;T extends AbstractPage&gt; implements Serializable{
      public AbstractBook() {
      }
  
      public abstract void addPage(T var1);
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public abstract class AbstractPage implements Serializable {
      public AbstractPage() {
      }
  }
  </code></pre>
  
  <p>And classes that are extended like these:</p>
  
  <pre><code>public class Book extends AbstractBook {
  
      private ArrayList&lt;Page&gt; allPages;
      private String title;
  
      Book(String title){
         allPages = new ArrayList&lt;Page&gt;();
      }
  
      @Override
      public void addPage(AbstractPage page) {
          this.allPages.add();
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class Page extends AbstractPage {
  
    private String content;
  
    public Page(String Content){
      this.content = Content;
    }
  
  }
  </code></pre>
  
  <p>In the <code>Book</code> class there is a method called <code>addPage</code>. I can pass a <code>Page</code> class object to this method, however; I can't add that object to the <code>ArrayList&lt;Page&gt; allPages</code>.</p>
  
  <p>Why exactly is that? I mean I think it is because the compiler expects type <code>AbstractPage</code> instead of <code>Page</code>. But why then I am capable of calling the method like <code>thisbook.addPage(pageObject)</code> ?</p>
  
  <p>So In other words, it lets me pass a subclass object, but it doesn't let me do anything with that passed object.</p>
  
  <p>And how do you get around this so that I can add that pageObject to the <code>ArrayList&lt;Page&gt; allPages</code> structure?</p>