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 Mwzad65
- {
- class Program
- {
- static void Main(string[] args)
- {
- Base a = new Base();
- a.Method();
- Base der = new Derived1();
- der.Method();
- Basee derr = new Derived2();
- derr.Method();
- Console.ReadKey();
- }
- public class Base
- {
- /// <summary>
- /// gdyby nie była wirtualna, to przy utworzenu obiektu zadziała polimorfizm statyczny (Base der = new Derived1();)
- /// czyli zadziała metoda Method z Base zamiast z Derived1
- /// </summary>
- virtual public void Method()
- {
- Console.WriteLine("baza");
- }
- }
- abstract public class Basee
- {
- /// <summary>
- /// możemy też użyć metody abstrakcyjnej, ale ta nie moze mieć żadnego ciała metody
- /// </summary>
- abstract public void Method();
- }
- public class Derived1: Base
- {
- override public void Method()
- {
- Console.WriteLine("111111111");
- }
- }
- public class Derived2 : Basee
- {
- override public void Method()
- {
- Console.WriteLine("222222222");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement