C# Programming - Inheritance

Exercise :: Inheritance - General Questions

6. 

What will be the output of the C#.NET code snippet given below?

namespace IndiabixConsoleApplication
{ 
    class Baseclass
    { 
        public void fun()
        { 
            Console.Write("Base class" + " ");
        } 
    } 
    class Derived1: Baseclass
    { 
        new void fun()
        {
            Console.Write("Derived1 class" + " "); 
        } 
    } 
    class Derived2: Derived1
    { 
        new void fun()
        { 
            Console.Write("Derived2 class" + " ");
        }
    }
    class Program
    { 
        public static void Main(string[ ] args)
        { 
            Derived2 d = new Derived2(); 
            d.fun(); 
        } 
    } 
}

A. Base class
B. Derived1 class
C. Derived2 class
D. Base class Derived1 class
E. Base class Derived1 class Derived2 class

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.

7. 

Which of the following should be used to implement a 'Has a' relationship between two entities?

A. Polymorphism
B. Templates
C. Containership
D. Encapsulation
E. Inheritance

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.

8. 

Which of the following is correct about the C#.NET snippet given below?

namespace IndiabixConsoleApplication
{ 
    class Baseclass
    { 
        public void fun()
        { 
            Console.WriteLine("Hi" + " ");
        } 
        public void fun(int i)
        {
            Console.Write("Hello" + " ");
        } 
    } 
    class Derived: Baseclass
    {
        public void fun()
        {
            Console.Write("Bye" + " ");
        } 
    } 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            Derived d; 
            d = new Derived(); 
            d.fun(); 
            d.fun(77);
        } 
    } 
}

A. The program gives the output as: Hi Hello Bye
B. The program gives the output as: Bye Hello
C. The program gives the output as: Hi Bye Hello
D. Error in the program

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.

9. 

In an inheritance chain which of the following members of base class are accessible to the derived class members?

  1. static
  2. protected
  3. private
  4. shared
  5. public

A. 1, 3
B. 2, 5
C. 3, 4
D. 4, 5

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.

10. 

Which of the following are reuse mechanisms available in C#.NET?

  1. Inheritance
  2. Encapsulation
  3. Templates
  4. Containership
  5. Polymorphism

A. 1, 4
B. 1, 3
C. 2, 4
D. 3, 5

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.