Skip to content

Overloading

Akkiraju Ivaturi

Akkiraju Ivaturi

Asked Sep 7, 2012, 7:18 PM EDT1 answer
Share
LinkedInX
What is displayed, and why?

using System;

class Base
{
public virtual void Foo(int x)
{
Console.WriteLine ("Base.Foo(int)");
}
}

class Derived : Base
{
public override void Foo(int x)
{
Console.WriteLine ("Derived.Foo(int)");
}

public void Foo(object o)
{
Console.WriteLine ("Derived.Foo(object)");
}
}

class Test
{
static void Main()
{
Derived d = new Derived();
int i = 10;
d.Foo(i);
}
} 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Akkiraju Ivaturi
    0
    Derived.Foo(object) is printed - when choosing an overload, if there are any compatible methods declared in a derived class, all signatures declared in the base class are ignored - even if they're overridden in the same derived class! 
    0