title: Changing the default value of an instance variable
body: <p>Suppose I have these codes (and the classes are in the same namespace):</p>
  
  <pre><code> class Animal
   {
      int numberOfLegs = 4; // initialized
      public int returnNumberOfLegs()
      {
        return numberOfLegs;
      }
   }
  
  class Snake
  {
     internal Animal myAnimalObject = new Animal();
     myAnimalObject.numberOfLegs = 0; // why is this line not allowed? 
  }
  
  class Program
  {
     public static void Main(string [] args)
     {
        Snake mySnakeObject = new Snake();
        Console.WriteLine("Snake");
        Console.WriteLine("Number of Legs: {0}", mySnakeObject.myAnimalObject.returnNumberOfLegs());
     }
  }
  </code></pre>
  
  <p>Observe the class Snake. When I place these 2 lines of code in Main(), it is possible/allowed and will work if I declare the variable numberOfLegs with the right access modifier. Why can't I do it in the class Snake itself? What should I do to allow it? </p>
  
  <p>Note that the 2nd line of code from class Snake is invalid and these are the errors it produced:
  1) Error    1   Invalid token '=' in class, struct, or interface member declaration
  2) Error    2   'myNamespaceName.Snake.myAnimalObject' is a 'field' but is used like a 'type'   </p>
  
  <p>Thanks. I just want to learn about this.</p>
  
  <p>Edit:
  Okay, thanks guys. I know about constructors and inheritance, but somehow, I'm being forced to do it "the hard and not-so-smart" way, for learning purposes(?). And that I even had to set the default value to 4. Thank you for your replies. Plus, I just made up these classes. </p>