evgeniyosipov

Override.cs

Apr 1st, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace ConsoleApplication1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             A a = new A();
  11.             A b = new B();
  12.  
  13.             a.Print();
  14.             b.Print();
  15.  
  16.             Console.WriteLine(a.Prop);
  17.             Console.WriteLine(b.Prop);
  18.  
  19.             A aa = new A();
  20.             B bb = new B();
  21.  
  22.             aa.Print();
  23.             bb.Print();
  24.  
  25.             Console.WriteLine(aa.Prop);
  26.             Console.WriteLine(bb.Prop);
  27.  
  28.         }
  29.     }
  30.  
  31.     class A
  32.     {
  33.         public virtual string Prop
  34.         {
  35.             get { return "Property of AAAA"; }
  36.         }
  37.  
  38.         public virtual void Print()
  39.         {
  40.             Console.WriteLine("AAAA");
  41.         }
  42.     }
  43.  
  44.     class B : A
  45.     {
  46.         public override string Prop
  47.         {
  48.             get { return "Property of BBBB"; }
  49.         }
  50.  
  51.         public override void Print()
  52.         {
  53.             Console.WriteLine("BBBB");
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment