Created
April 22, 2012 17:25
-
-
Save eogas/2465479 to your computer and use it in GitHub Desktop.
Inheritance demonstration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace InheritanceTest | |
{ | |
class BaseClass | |
{ | |
public virtual void Print() | |
{ | |
Console.WriteLine("Base class printing!"); | |
} | |
} | |
class ChildA : BaseClass | |
{ | |
public override void Print() | |
{ | |
Console.WriteLine("Child A printing!"); | |
} | |
} | |
class ChildB : BaseClass | |
{ | |
public override void Print() | |
{ | |
Console.WriteLine("Child B printing!"); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
List<BaseClass> bases = new List<BaseClass>(); | |
bases.Add(new BaseClass()); | |
bases.Add(new ChildB()); | |
bases.Add(new ChildA()); | |
bases.Add(new ChildB()); | |
bases.Add(new ChildA()); | |
bases.Add(new BaseClass()); | |
bases.ForEach(b => b.Print()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment