Skip to content

Instantly share code, notes, and snippets.

@yungtechboy1
Created March 13, 2017 15:25
Show Gist options
  • Save yungtechboy1/3abff2bd2e478caef14a6b2cfa8a51fb to your computer and use it in GitHub Desktop.
Save yungtechboy1/3abff2bd2e478caef14a6b2cfa8a51fb to your computer and use it in GitHub Desktop.
namespace Polymorphism
{ public class A
{
private String You_Cant_See = "Boo!0";
public void Foo()
{
Console.WriteLine("A::Foo()");
}
}
class B : A
{
public new void Foo()
{
Console.WriteLine("B::Foo()");
}
class Test
{
static void Main(string[] args)
{
A a;
//B b;
a = new A();
b = new B();
a.Foo(); // output --> "A::Foo()"
b.Foo(); // output --> "B::Foo()"
a = new B();
a.Foo(); // output --> "A::Foo()"
//Need it to output B::Foo() inorder for my method to work
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment