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 ***]
}
}
Discussion:
17 comments Page 2 of 2.
Ajesh said:
1 decade ago
What is base.i?
Divya said:
1 decade ago
By default csharp class members are private when the access specifier is absent. So, it can't access child class features (derived class features).
Chandra Shekhar said:
1 decade ago
If we remove protected modifier by default it become private which is not accessible in child class.
Sudhakar said:
1 decade ago
Private is the default access modifier for members, if you don't specify access specifier then compiler assumes it is private, private members are not accessible in derived class hence you will get error.
KUMAR said:
1 decade ago
Removing protected keyword means these variable private data type. So this variable use only base class, does not inherited child class.
Neelendu said:
1 decade ago
Removing protected keyword become private. Because default scope of class member is private which is not accessible by other class or type.
Here use of protected is:
Only child class access this data.
Here use of protected is:
Only child class access this data.
Ravi said:
1 decade ago
Because on removing protected keyword int I will become public by default, and now for derived there would be two i variable.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers