Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Oroklodes
- {
- abstract class Human
- {
- public abstract void Knocking(); //nem tartalmaz implementációt
- }
- class Butcher : Human
- {
- public override void Knocking();
- }
- abstract class Scientist : Human
- {
- protected string name; //védett láthatóság
- public virtual void Knocking()
- {
- Console.WriteLine("Knock-knock, this is {0}", this.name);
- }
- public Scientist(string name)
- {
- this.name = name;
- }
- }
- class Physicist : Scientist //fizikus örököl a tudós osztálytól
- {
- protected int iq;
- public Physicist(string name, int iq)
- : base(name) //valemlyik osének a példányára mutat
- {
- this.iq = iq;
- }
- public override void Knocking()
- {
- for (int i = 0; i < 3; i++)
- {
- base.Knocking();
- System.Threading.Thread.Sleep(1000);
- }
- }
- }
- class NuclearPhysicist : Physicist
- {
- public NuclearPhysicist(string name, int iq)
- : base(name, iq)
- {
- }
- public override void Knocking()
- {
- base.Knocking();
- Console.WriteLine("Még valami más");
- }
- public void Publish()
- {
- Console.WriteLine("Írtam egy cikket!!!!!44444!!");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- // Scientist A = new Scientist("Amy");
- Physicist S = new Physicist("Sheldon", 150);
- Scientist R = new Physicist("Rajesh", 145);
- Physicist L = new NuclearPhysicist("Leonard", 145);
- Scientist[] scientists = new Scientist[] { S, R, L };
- foreach (Scientist s in scientists)
- {
- s.Knocking();
- if (s is NuclearPhysicist)
- {
- (s as NuclearPhysicist).Publish();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement