title: Java - How to check if two objects, from the same abstract class, are equal
body: <p>I'm writing a program which contains an abstract class of 'Book', and I have two classes ('LearnBook' and 'ReadingBook') which inherit from 'Book'.</p>
  
  <p>Book:</p>
  
  <pre><code>Public abstract class Book {
  protected String name;
  protected String author;
  </code></pre>
  
  <p>LearningBook:</p>
  
  <pre><code>public class LearningBook extends Book {
  private String subject;
  </code></pre>
  
  <p>ReadingBook:</p>
  
  <pre><code>public class ReadingBook extends Book {
  private int numberOfPages;
  </code></pre>
  
  <p>At the main class I have Book array which can include any instance of Book.</p>
  
  <p>I want to add a method which checks if two Book objects are exactly the same, to prevent duplicating in the Book array. it looks like this:</p>
  
  <pre><code>public boolean sameBookCheck(Book book1, Book book2)
  </code></pre>
  
  <p>So my first idea was to write an isEqual() method in the Book class, which checks if the "name" and the "author" are equals.
  But then I need to check if it's a learning book or reading book so I could know if I need to compare the "subject" value or the "numberOfPage" value.</p>
  
  <p>I have no idea how to do it and I'd appreciate your help.</p>