Q&A: 30 second OOP trick question

To get a fast answer how good job candidate is in OOP thinking give him up to 30 second to give you an answer what is the output of next console application

using System;

namespace Example
{
    class Program    {
        static void Main(string[] args)
        {
            TypeB example = new TypeB();
            Console.WriteLine(example.ToString());
            Console.WriteLine(((TypeA)example).ToString());
            Console.WriteLine(((object)example).ToString());

            Console.ReadLine();
        }
    }

    public class TypeA:System.Object
    {
        public override string ToString()
        {
            return “Hello from TypeA”;
        }
    }

    public class TypeB : TypeA
    {
        public override string ToString()
        {
            return “Hello from TypeB”;
        }
    }
}

 

Technorati tags: , , , ,

Advertisements

Posted on April 5, 2007, in Uncategorized. Bookmark the permalink. 2 Comments.

  1. You’re confused as to what makes a good developer.  In fact, if you wrote convoluted code like this for me, I’d fire you on the spot.

  2. That code is not a code I would write in real world, that's a short snippet which I think it could be given to some job candidate to get a fast view on how he understands inheritance
    One more time, it is a trick question for interviews

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: