Skip to content

Instantly share code, notes, and snippets.

@joladev
Last active December 15, 2015 07:09
Show Gist options
  • Save joladev/5221080 to your computer and use it in GitHub Desktop.
Save joladev/5221080 to your computer and use it in GitHub Desktop.
Inheritance and new keyword
using System;
class Program
{
public class A
{
public void print()
{
Console.WriteLine("A");
}
}
public class B : A
{
public new void print()
{
Console.WriteLine("B");
}
}
static void Main(string[] args)
{
B b = new B();
A a = b as A;
a.print(); // prints A
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment