Skip to content

Instantly share code, notes, and snippets.

@eogas
Created April 22, 2012 17:25
Show Gist options
  • Save eogas/2465479 to your computer and use it in GitHub Desktop.
Save eogas/2465479 to your computer and use it in GitHub Desktop.
Inheritance demonstration
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