C Potential Interview Question Too hard

0 votes

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?

Jun 7 in C# by pranav
• 2,580 points
30 views

1 answer to this question.

0 votes
This isn't a question I'd ask in an interview. I know the answer and why it's correct, but something like this should only happen once in a while, so it shouldn't be a problem. Knowing the solution doesn't reveal much about a candidate's coding ability.

Even if A.Foo is virtual and B overrides it, the result will be the same.
answered Jun 7 by rajiv
• 1,620 points

Related Questions In C#

0 votes
0 answers

ReverseString, a C# interview-question

I was asked for my 'input' on ...READ MORE

Jun 11 in C# by jyoti
• 1,240 points
15 views
0 votes
1 answer

Are these interview questions too challenging for beginners?

As a new employee, I would expect ...READ MORE

answered Jun 11 in C# by pranav
• 2,580 points
25 views
0 votes
1 answer

Simple VB or C# questions for an interview

The difficulty with asking language-specific questions for ...READ MORE

answered Jun 13 in C# by krishna
• 2,540 points
19 views
0 votes
1 answer

What is the best C# to VB.net converter

Telerik has a solid SharpDevelop-based converter that ...READ MORE

answered May 30 in C# by rajiv
• 1,620 points
69 views
0 votes
1 answer
0 votes
2 answers

Is there a .NET equivalent to Apache Hadoop?

Hadoop is a Java-based platform. So, to ...READ MORE

answered Jul 16, 2020 in Big Data Hadoop by Suhana
• 340 points
668 views
0 votes
1 answer

Validate String against USPS State Abbreviations

Try something like this: private static String states ...READ MORE

answered Sep 20, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
229 views
0 votes
1 answer

Authenticate on an ASP.Net Forms Authorization website from a console app

Essentially, we need to record a regular ...READ MORE

answered Sep 20, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
263 views
0 votes
1 answer

Good C# interview questions book

If you're simply familiar with the foundations ...READ MORE

answered Jun 7 in C# by rajiv
• 1,620 points
18 views
0 votes
1 answer

Convert VB.NET --> C# Projects

You may decompile whole Assemblies into Visual ...READ MORE

answered May 30 in C# by rajiv
• 1,620 points
25 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP