title: Overriding and Inheritance in C#
body: <p>Ok, bear with me guys and girls as I'm learning.  Here's my question.</p>
  
  <p>I can't figure out why I can't override a method from a parent class.  Here's the code from the base class (yes, I pilfered the java code from an OOP book and am trying to rewrite it in C#).</p>
  
  <pre><code>using System;
  
  public class MoodyObject
  {
      protected String getMood()
      {
          return "moody";
      }
  
      public void queryMood()
      {
          Console.WriteLine("I feel " + getMood() + " today!");
      }
  }
  </code></pre>
  
  <p>and here are my other 2 objects that inherit the base class (MoodyObject):</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ConsoleApplication1
  {
      public class SadObject: MoodyObject
      {
          protected String getMood()
          {
              return "sad";
          }
  
          //specialization
          public void cry()
          {
              Console.WriteLine("wah...boohoo");
          }
      }
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ConsoleApplication1
  {
      public class HappyObject: MoodyObject
      {
          protected String getMood()
          {
              return "happy";
          }
  
          public void laugh()
          {
              Console.WriteLine("hehehehehehe.");
          }
      }
  }
  </code></pre>
  
  <p>and here is my main:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              MoodyObject moodyObject = new MoodyObject();
              SadObject sadObject = new SadObject();
              HappyObject happyObject = new HappyObject();
  
              Console.WriteLine("How does the moody object feel today?");
              moodyObject.queryMood();
              Console.WriteLine("");
              Console.WriteLine("How does the sad object feel today?");
              sadObject.queryMood();
              sadObject.cry();
              Console.WriteLine("");
              Console.WriteLine("How does the happy object feel today?");
              happyObject.queryMood();
              happyObject.laugh();
          }
      }
  }
  </code></pre>
  
  <p>As you can see, pretty basic stuff, but here's the output:</p>
  
  <blockquote>
    <p>How does the moody object feel today?
    I feel moody today!</p>
    
    <p>How does the sad object feel today? I
    feel moody today! wah...boohoo</p>
    
    <p>How does the happy object feel today?
    I feel moody today! hehehehehehe.
    Press any key to continue . . .</p>
  </blockquote>
  
  <p>Not as I expected.  I've tried to make the base method virtual and calling override when trying to override it and that just gets me this error "cannot override inherited member 'MoodyObject.getMood()' because it is not marked virtual, abstract, or override".  I also tried it without the virtual and override and it thinks I'm trying to hide the base method.  Again, I'm new to OOP and would appreciate any guidance.</p>
  
  <p><strong>EDITED TO ADD:  I found it!  The MoodyObject.cs was only a "solution item" in the solution explorer as opposed to a "ConsoleApplication1" item.  I dragged it down to where it belonged in the solution explorer and voila!  It works now.  I marked Luc's answer below as the answer because he offered the help I needed to get to where I have it resolved... I'm learning so much here.  It's amazing and you guys and girls are crazy smart!</strong></p>