C# Programming - Inheritance - Discussion

Discussion Forum : Inheritance - General Questions (Q.No. 3)
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.
Discussion:
16 comments Page 2 of 2.

Arun saraswat said:   1 decade ago
How inheritance work? and in this case how we are going to be inherit the function ?

Siddesh said:   1 decade ago
Even if we declare it public it is available to the sub classes.

Amr said:   8 years ago
I do not understand the third option. Please explain it for me.
(1)

Anju said:   7 years ago
Of course, the base class constructor will be called first.

Radhika said:   1 decade ago
How constructor to index class?

Mash said:   1 decade ago
Answer seems all right to me.


Post your comments here:

Your comments will be displayed after verification.