title: Passing object reference of different classes through Object class
body: <p>I have a utility class <code>A</code> which contains <code>operation()</code> method . There are two other classes <code>B</code> and <code>C</code>. <code>B</code> and <code>C</code> contains a method <code>add()</code>. I want to call <code>add()</code> method of class <code>B</code> or <code>C</code> from class <code>A</code> <code>operation()</code> method.</p>
  <p>Depending upon the reference passed of a class for ex : <code>B</code> or <code>C</code> I would like the compiler to decide which class of <code>add()</code> method to call.</p>
  <p>So, for this, I tried like this, by passing reference of class <code>B</code> I want to call <code>add()</code> method of <code>B</code></p>
  <pre><code>new A().operation( new B())
  </code></pre>
  <p>Now in A class, I am receiving the reference in <code>Object</code> class as it should be able to hold the reference of both <code>B</code> and <code>C</code> class</p>
  <p>so, the code is</p>
  <pre><code>class A{
  public void operation(Object obj){
  obj.add();
  }   
  }
  </code></pre>
  <p>I am getting compilation error that it couldn't add() method in <code>Object</code> class, My question is why is it finding the method in Object class, It holds the object reference of class <code>B</code>. Am i doing it correctly or is there a better approach in this scenario?</p>