Are private class-level variables inherited ?

 Posted by Bharathi Cherukuri on 4/26/2012 | Category: .NET Framework Interview questions | Views: 1533 | Points: 40
Answer:

yes, Private class level variables are inheritable, but they are not accessible.

Example:

public class BaseClass

{
private const int _aNumber = 5;
public int ReturnANumber() { return _aNumber; }
}
public class DClass : BaseClass
{
public void SomeMethod()
{
// This is indirectly accessing a private implemented in the class
// this derives from, but existing inside this class.
int numbery = this.ReturnANumber();
}
}
public class Whatever
{
public void AMethod(DClass someDClass)
{
int thisIsNumberFive = someDClass.ReturnANumber();
}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response