title: Why would one create a Base Class object with reference to the Derived Class
body: <p>I was practicing inheritance, using a test program in C# and I found out that the following statement does not throw an error:</p>
  
  <pre><code>BaseClass baseObj = new DerivedClass();
  </code></pre>
  
  <p>Why is this statement allowed and is there a situation where this statement would be useful to a programmer?</p>
  
  <p>Here is my test program:</p>
  
  <pre><code>class BaseClass
  {
      public void show()
      {
          Console.WriteLine("Base Class!");
  
      }
  }
  
  class DerivedClass : BaseClass
  {
      public void Display()
      {
          Console.WriteLine("Derived Class!");            
      }
  }
  
  class Result
  {
      public static void Main()
      {            
          BaseClass baseObj = new DerivedClass();
          baseObj.show();
      }
  }
  </code></pre>