Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 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 Oroklodes
  8. {
  9.     abstract class Human
  10.     {
  11.         public abstract void Knocking(); //nem tartalmaz implementációt
  12.  
  13.     }
  14.  
  15.     class Butcher : Human
  16.     {
  17.         public override void Knocking();
  18.  
  19.     }
  20.     abstract class Scientist : Human
  21.     {
  22.         protected string name; //védett láthatóság
  23.  
  24.         public virtual void Knocking()
  25.         {
  26.             Console.WriteLine("Knock-knock, this is {0}", this.name);
  27.         }
  28.  
  29.         public Scientist(string name)
  30.         {
  31.             this.name = name;
  32.         }
  33.     }
  34.  
  35.     class Physicist : Scientist //fizikus örököl a tudós osztálytól
  36.     {
  37.         protected int iq;
  38.  
  39.         public Physicist(string name, int iq)
  40.             : base(name) //valemlyik osének a példányára mutat
  41.         {
  42.             this.iq = iq;
  43.         }
  44.  
  45.         public override void Knocking()
  46.         {
  47.             for (int i = 0; i < 3; i++)
  48.             {
  49.                 base.Knocking();
  50.                 System.Threading.Thread.Sleep(1000);
  51.             }
  52.         }
  53.     }
  54.  
  55.     class NuclearPhysicist : Physicist
  56.     {
  57.         public NuclearPhysicist(string name, int iq)
  58.             : base(name, iq)
  59.         {
  60.  
  61.         }
  62.  
  63.         public override void Knocking()
  64.         {
  65.             base.Knocking();
  66.             Console.WriteLine("Még valami más");
  67.         }
  68.  
  69.         public void Publish()
  70.         {
  71.             Console.WriteLine("Írtam egy cikket!!!!!44444!!");
  72.         }
  73.     }
  74.     class Program
  75.     {
  76.         static void Main(string[] args)
  77.         {
  78.  
  79.         //   Scientist A = new Scientist("Amy");
  80.  
  81.             Physicist S = new Physicist("Sheldon", 150);
  82.  
  83.             Scientist R = new Physicist("Rajesh", 145);
  84.  
  85.             Physicist L = new NuclearPhysicist("Leonard", 145);
  86.  
  87.  
  88.             Scientist[] scientists = new Scientist[] { S, R, L };
  89.             foreach (Scientist s in scientists)
  90.             {
  91.                 s.Knocking();
  92.                 if (s is NuclearPhysicist)
  93.                 {
  94.                     (s as NuclearPhysicist).Publish();
  95.                 }
  96.  
  97.  
  98.             }
  99.  
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement