Manish Singh

Manish Singh

  • NA
  • 7.6k
  • 4.4m

Identify which Foo method will be called.

Nov 24 2011 11:39 AM
Hi..........
 
Ques :
My problem is Without running this code, identify which Foo method will be called:


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 method? And why?

Answers (2)