Determine which Foo method will be invoked without running the code:
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 );
}
Which technique? Then why? Run the code without trying to trick it.
I came across this problem online, and I think I'll use it as a question in an interview because I enjoy it. Link: http://netpl.blogspot.com/2008/06/c-puzzle-no8-beginner.html