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, 2022 in C# by pranav
• 2,590 points
417 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, 2022 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, 2022 in C# by jyoti
• 1,240 points
358 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, 2022 in C# by pranav
• 2,590 points
805 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, 2022 in C# by krishna
• 2,820 points
461 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, 2022 in C# by rajiv
• 1,620 points
1,591 views
0 votes
0 answers

C# Potential Interview Question…Too hard?

Determine which Foo method will be invoked ...READ MORE

Sep 27, 2022 in C# by krishna
• 2,820 points
408 views
0 votes
1 answer

SQLite.Net not being able to create text file in Win IoT Library!

That exception comes when access limited to ...READ MORE

answered Aug 3, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,006 views
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
1,734 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
945 views
0 votes
1 answer

Good C# interview questions book

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

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

Convert VB.NET --> C# Projects

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

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