Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApplication1
  4. {
  5.     class Parent
  6.     {
  7.         protected string SomeProperty
  8.         {
  9.             get { return "Parent Property"; }
  10.         }
  11.  
  12.         public void PrintProperty()
  13.         {
  14.             Console.WriteLine(SomeProperty);
  15.         }
  16.     }
  17.  
  18.     class Child : Parent
  19.     {
  20.         protected new string SomeProperty
  21.         {
  22.             get { return "Child Property"; }
  23.         }
  24.     }
  25.  
  26.     internal class Program
  27.     {
  28.         public static void Main(string[] args)
  29.         {
  30.             var child = new Child();
  31.             child.PrintProperty();
  32.             // Expected: Child Property
  33.             // Actual:   Parent Property
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement