pol9na

Виртуальные методы

Mar 31st, 2020
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Study
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             DoAction(new Trader());
  14.             DoAction(new NPC());
  15.         }
  16.         static void DoAction(NPC npc)
  17.         {
  18.             npc.Action();
  19.         }
  20.     }
  21.     class NPC
  22.     {
  23.         public virtual void Action()
  24.         {
  25.             Console.WriteLine("I,m npc ");
  26.         }
  27.  
  28.     }
  29.     class Trader : NPC
  30.     {
  31.         public override void Action()
  32.         {
  33.             Console.WriteLine("I,m trader");
  34.            
  35.         }
  36.  
  37.     }
  38.     class Warrior : NPC
  39.     {
  40.    
  41.     }
  42. }
Add Comment
Please, Sign In to add comment