Guest User

Untitled

a guest
Oct 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. public class test4 : test2
  2. {
  3.   public test4 ()
  4.   {
  5.     this.name = "test4";
  6.   }
  7.  
  8.   public override void DoIt()
  9.   {
  10.     // call the base methods DoIt first
  11.     base.DoIt();
  12.     // then do this
  13.     System.Console.WriteLine("test 4 derived" );
  14.   }
  15. }
  16.  
  17. public class test3 : test2
  18. {
  19.   public test3 ()
  20.   {
  21.     this.name = "test3";
  22.   }
  23.  
  24.   // override means it has overriden a base class virtual
  25.   // method
  26.   public override void DoIt()
  27.   {
  28.     System.Console.WriteLine("test3 derived" );
  29.   }
  30. }
  31.  
  32. public class test2
  33. {
  34.   public string name { get; protected set; }
  35.   public test2 ()
  36.   {
  37.     this.name = "test2";
  38.   }
  39.  
  40.   // virtual means that this method can be overriden
  41.   public virtual void DoIt()
  42.   {
  43.     System.Console.WriteLine("test2 base" );
  44.   }
  45. }
  46.  
  47. public class test
  48. {
  49.   static void Main ()
  50.   {
  51.     test3 t3 = new test3();
  52.     test4 t4 = new test4();
  53.  
  54.     System.Console.WriteLine(t3.name);
  55.     t3.DoIt();
  56.  
  57.     System.Console.WriteLine(t4.name);
  58.     t4.DoIt();
  59.   }
  60. }
Add Comment
Please, Sign In to add comment