C# Programming - Inheritance - Discussion

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

Chandra Shekhar said:   1 decade ago
If we remove protected modifier by default it become private which is not accessible in child class.

Karthi said:   10 years ago
Hi,

Both option A and B are same. May I know what is the difference between them?

Sushil said:   9 years ago
But we can't use base keyword under a static block of a derived class.

Govind said:   1 decade ago
Where is create object name base ?

It is directly used it.

Pavan said:   1 decade ago
What is the difference between base.i and mybase.i?

Somu said:   1 decade ago
If I remove protected then it show error. Why?

Ajesh said:   1 decade ago
What is base.i?


Post your comments here:

Your comments will be displayed after verification.