Mega Code Archive

 
Categories / C# / Class Interface
 

Method override 3

/* Learning C#  by Jesse Liberty Publisher: O'Reilly  ISBN: 0596003765 */  using System;  class Dog  {      private int weight;      // constructor      public Dog(int weight)      {          this.weight = weight;      }      // override Object.ToString      public override string ToString()      {          return weight.ToString();      }  }  public class TesterOverride  {      static void Main()      {          int i = 5;          Console.WriteLine("The value of i is: {0}", i.ToString());          Dog milo = new Dog(62);          Console.WriteLine("My dog Milo weighs {0} pounds", milo.ToString());      }  }