C# Programming - Inheritance

Why should I learn to solve C# Programming questions and answers section on "Inheritance"?

Learn and practise solving C# Programming questions and answers section on "Inheritance" to enhance your skills so that you can clear interviews, competitive examinations, and various entrance tests (CAT, GATE, GRE, MAT, bank exams, railway exams, etc.) with full confidence.

Where can I get the C# Programming questions and answers section on "Inheritance"?

IndiaBIX provides you with numerous C# Programming questions and answers based on "Inheritance" along with fully solved examples and detailed explanations that will be easy to understand.

Where can I get the C# Programming section on "Inheritance" MCQ-type interview questions and answers (objective type, multiple choice)?

Here you can find multiple-choice C# Programming questions and answers based on "Inheritance" for your placement interviews and competitive exams. Objective-type and true-or-false-type questions are given too.

How do I download the C# Programming questions and answers section on "Inheritance" in PDF format?

You can download the C# Programming quiz questions and answers section on "Inheritance" as PDF files or eBooks.

How do I solve C# Programming quiz problems based on "Inheritance"?

You can easily solve C# Programming quiz problems based on "Inheritance" by practising the given exercises, including shortcuts and tricks.

Exercise : Inheritance - General Questions
1.
Which of the following can be facilitated by the Inheritance mechanism?
  1. Use the existing functionality of base class.
  2. Overrride the existing functionality of base class.
  3. Implement new functionality in the derived class.
  4. Implement polymorphic behaviour.
  5. Implement containership.
1, 2, 3
3, 4
2, 4, 5
3, 5
Answer: Option
Explanation:
No answer description is available. Let's discuss.

2.
Which of the following statements should be added to the subroutine fun( ) if the C#.NET code snippet given below is to output 9 13?
class BaseClass
{
    protected int i = 13;
}
class Derived: BaseClass
{
    int i = 9; 
    public void fun()
    {
        // [*** Add statement here ***]
    } 
}
Console.WriteLine(base.i + " " + i);
Console.WriteLine(i + " " + base.i);
Console.WriteLine(mybase.i + " " + i);
Console.WriteLine(i + " " + mybase.i);
Console.WriteLine(i + " " + this.i);
Answer: Option
Explanation:
No answer description is available. Let's discuss.

3.
Which of the following statements are correct about the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{ 
    class index
    {
        protected int count;
        public index()
        {
            count = 0;
        }
    }
    class index1: index
    {
        public void increment()
        {
            count = count +1;
        }
    }
    class MyProgram
    {
        static void Main(string[] args)
        {
            index1 i = new index1(); 
            i.increment(); 
        }
    }
}
  1. count should be declared as public if it is to become available in the inheritance chain.
  2. count should be declared as protected if it is to become available in the inheritance chain.
  3. While constructing an object referred to by i firstly constructor of index class will be called followed by constructor of index1 class.
  4. Constructor of index class does not get inherited in index1 class.
  5. count should be declared as Friend if it is to become available in the inheritance chain.
1, 2, 5
2, 3, 4
3, 5
4, 5
None of these
Answer: Option
Explanation:
No answer description is available. Let's discuss.

4.
What will be the size of the object created by the following C#.NET code snippet?
namespace IndiabixConsoleApplication
{ 
    class Baseclass
    {
        private int i; 
        protected int j; 
        public int k;
    }
    class Derived: Baseclass
    {
        private int x; 
        protected int y; 
        public int z;
    }
    class MyProgram
    { 
        static void Main (string[ ] args)
        { 
            Derived d = new Derived();
        } 
    } 
}
24 bytes
12 bytes
20 bytes
10 bytes
16 bytes
Answer: Option
Explanation:
No answer description is available. Let's discuss.

5.
Which statement will you add in the function fun() of class B, if it is to produce the output "Welcome to IndiaBIX.com!"?
namespace IndiabixConsoleApplication
{ 
    class A
    {
        public void fun()
        {
            Console.Write("Welcome");
        } 
    } 
    class B: A
    {
        public void fun()
        {
            // [*** Add statement here ***]
            Console.WriteLine(" to IndiaBIX.com!");
        } 
    } 
    class MyProgram
    { 
        static void Main (string[ ] args)
        { 
            B b = new B(); 
            b.fun();
        } 
    } 
}
base.fun();
A::fun();
fun();
mybase.fun();
A.fun();
Answer: Option
Explanation:
No answer description is available. Let's discuss.