title: calling super.equals() in derived class while overriding equals
body: <p>I have a base class with age and name as instance members and derived class with bonus. I am overriding equals in Derived class. I know how equals works in Java when there is a single base class. But I am not able to understand how it works in case of inheritance. I want to check if two derived objects are equal.</p>
  
  <p>I was expecting the output to be <br/>
  This class = Base, Other class = Derived <br/>
  instead the output is 
  This class = Derived, Other class = Derived <br/></p>
  
  <p>What is super in equals method of derived class exactly doing?Isnt it referring to Base?</p>
  
  <pre><code>&lt;br/&gt;
  
  public class Base{
  
      private int age;
      private String name;
  
      public Base(int age, String name){
          this.age = age;
          this.name = name;
      }
  
      public int getAge(){
          return age;
      }
  
      public String getName(){
          return name;
      }
  
      @Override
      public boolean equals(Object otherBase){
  
          //Check if both the references refer to same object
          if(this == otherBase){
              return true;
          }
  
          if(otherBase == null){
              return false;
          }
  
          System.out.println("This class       ="+this.getClass().getCanonicalName()+", Other class = "+otherBase.getClass().getCanonicalName());
  
          if(this.getClass() != otherBase.getClass()){
              return false;
          }
  
          if(! (otherBase instanceof Base)){
              return false;
          }
  
          Base other = (Base) otherBase;
  
          return this.age == other.age &amp;&amp; this.name.equals(other.name);
         }
  
  
      public static void main(String[] args){
          Derived d1 = new Derived(10,6,"shri");
          Derived d2 = new Derived(10,5, "shri");
          if(d1.equals(d2)){
              System.out.println("Equal");
          }else{
              System.out.println("Not Equal");
          }
      }
  }
  
  class Derived extends Base{
  
      private int bonus;
  
      public int getBonus(){
          return bonus;
      }
  
      public Derived(int bonus, int age, String name){
          super(age, name);
          this.bonus = bonus;
      }
  
      @Override
      public boolean equals(Object otherDerived){
          if(!(super.equals(otherDerived))){
              return false;
          }
  
          Derived derived = (Derived) otherDerived;
          return bonus == derived.bonus;
      }
  }
  </code></pre>