Last active
December 15, 2015 07:09
-
-
Save joladev/5221080 to your computer and use it in GitHub Desktop.
Inheritance and new keyword
This file contains hidden or 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; | |
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