2
Answers

Identify which Foo method will be called.

Manish Singh

Manish Singh

13y
1.3k
1
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)