title: Calling a function using Object type reference (holding a different instance)
body: <p>I have a Dog class described as:</p>
  
  <pre><code>class Dog {
  //data members
  void bark() {
     //Bark Algorithm
    }
  }
  </code></pre>
  
  <p>Now in another class which has the main method and in the main method, if I do the following:</p>
  
  <pre><code>Object dog = new Dog();
  dog.bark();
  </code></pre>
  
  <p>Shouldn't it work as the "dog" reference is holding a Dog instance? Why is this not valid?</p>
  
  <p>The language used here is Java.</p>
  
  <p>Thanks for the help in advance.</p>