Ques : My problem is Without running this code, identify which
Foo method will be called:Code :
C#
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 );
}

Karthik AgarwalRank #2,270 · 620 reputationPosted Nov 24, 2011, 7:03 AM EST
{
/* note that A::Foo and B::Foo are not related at all */
public void Foo( double n )
{
Console.WriteLine( "B::Foo" );
}
}
the above class will be called bcoz of this line
B b = new B();Amit MaheshwariRank #475 · 5.2K reputationPosted Nov 24, 2011, 7:05 AM EST
i have understand your question here and the output will be
Console.WriteLine( "B::Foo");
Because it will cast automatictly and use the first without going further in the inheritance.