If we inherit a class do the private variables also get
inherited ?

Answers were Sorted based on User's Feedback



If we inherit a class do the private variables also get inherited ?..

Answer / nitin kumar tomar

Yes but they are not accessible

Is This Answer Correct ?    34 Yes 3 No

If we inherit a class do the private variables also get inherited ?..

Answer / ganni

yes they are inherited, but cannot be accessible. for
that we need to use properties concept.

Is This Answer Correct ?    11 Yes 1 No

If we inherit a class do the private variables also get inherited ?..

Answer / ashwini chavan

yes they are inherited, but cannot be accessible.because
when we inherite the class then all data member and function
member of the base class are accesed in the derive class
attomaticaly.but private specifier is accesible only it's
own class out side class can't acces that private member
when we try it then we got error

Is This Answer Correct ?    4 Yes 0 No

If we inherit a class do the private variables also get inherited ?..

Answer / jigar

Yes, the variables are inherited but can not be accessed directly by the class interface.

Is This Answer Correct ?    4 Yes 1 No

If we inherit a class do the private variables also get inherited ?..

Answer / sukriya

You can use private only with a nested class, one that is
defined within another class. The result is that the
private class is accessible only from within the containing
class
try this code
public class BaseClass
{
public virtual void TraceSelf()
{
Console.WriteLine("BaseClass");
Privateclass pc = new Privateclass();
pc.Self();
}

private class Privateclass
{
public void Self()
{
Console.WriteLine("PrivateClass");
}
}

}
public class SubClass : BaseClass
{
public override void TraceSelf()
{
//Privateclass pc = new Privateclass();
//pc.Self();
Console.WriteLine("SubClass");
}
}
static void Main(string[] args)
{
BaseClass obj = new BaseClass();
obj.TraceSelf(); // Outputs "BaseClass"

SubClass obj2 = new SubClass();
obj2.TraceSelf();

Console.ReadKey();
}
this is the main Program for the code

Is This Answer Correct ?    2 Yes 2 No

If we inherit a class do the private variables also get inherited ?..

Answer / javed khan

No, We cant inherit private member of base class. We got
error like " member is inaccessible due to its protection
level."

Is This Answer Correct ?    7 Yes 13 No

Post New Answer

More C Sharp Interview Questions

write program in c# using this instructions name avinash varma ,work experiance<2,nochildren his work experiance is higher than 5 years,more than one children one children name is diwakar,number of years of work eperiance at current company is the ratio of children and work experiance is 0.21 to 0.5

0 Answers  


Difference between multi-level and multiple inheritance?

4 Answers   Microsoft,


What's the difference between WindowsDefaultLocation and WindowsDefaultBounds?

0 Answers   BirlaSoft,


Why we use dll in c#?

0 Answers  


4. Describe the process when we send a request URL? And who is responsible for that?

0 Answers   Mphasis,






What is protected internal modifier in C#?

0 Answers   Arigo Infotech,


How you will connect to windows directory in c#?

2 Answers   HP, nTech Solutions,


What are the Types of configuration files and their differences

0 Answers   BirlaSoft,


What is sorted list in c#?

0 Answers  


Explain concurrency with aop?

0 Answers  


What is the reason behind the invention of c#?

0 Answers  


what is Diff Gram

2 Answers   HCL, Nippon,


Categories