Csharp.Net output type question

Q.  Trace the output
namespace A
{
    class MyClass
    {
        public void fun()
        {
            Console.WriteLine( " C # is fun " );
        }
    }
    namespace B
    {
        class MyClass
        {
            public void fun()
            {
                Console.WriteLine( " C # is interesting " );
            }
        }
    }
}
Consider the above code what will be the output of following program
class Program
    {
        static void Main(string[] args)
        {
            A.B.MyClass obj = new A.B.MyClass();

            obj.fun();

        }

    }

- Published on 31 Aug 15

a. C # is interesting
b. C # is fun
c. compile time error
d. None of the above

ANSWER: C # is interesting
 
In the given problem there is nested namespace. The code A.B.MyClass obj = new A.B.MyClass(); will create the object that will refer to namespace B, so the inner class method will be called and answer will be
“C # is interesting”

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)