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;
- namespace Generics
- {
- class A
- {
- public virtual void show()
- {
- Console.WriteLine("Hello: Base Class!");
- Console.ReadLine();
- }
- }
- class B : A
- {
- public override void show()
- {
- Console.WriteLine("Hello: Derived Class!");
- Console.ReadLine();
- }
- }
- class C : B
- {
- public new void show()
- {
- Console.WriteLine("Am Here!");
- Console.ReadLine();
- }
- }
- class Polymorphism
- {
- public static void Main()
- {
- A a1 = new A();
- a1.show();
- B b1 = new B();
- b1.show();
- C c1 = new C();
- c1.show();
- A a2 = new B();
- a2.show();
- A a3 = new C();
- a3.show();
- B b3 = new C();
- b3.show();
- }
- }
- }
- // Source: http://www.codeproject.com/Articles/816448/Virtual-vs-Override-vs-New-Keyword-in-Csharp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement