Don't run this code and answer which foo will be called. Why? Which method?
class A
{
public void Foo( int n )
{
Console.WriteLine( "A::Foo" );
}
}
class B : A
{
/* note that A::Foo and B::Foo are not related at all */
public void Foo( double n )
{
Console.WriteLine( "B::Foo" );
}
}
static void Main( string[] args )
{
B b = new B();
/* which Foo is chosen? */
b.Foo( 5 );
}
I came across this problem here: https://www.wiktorzychla.com/2008/06/c-puzzle-no8-beginner.html
I plan to use this as an interview question. Any ideas?