What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 17247 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > .NET Framework Interview Questions > Are private class-level variables inheri ...

Are private class-level variables inherited ?

Interview question and answer by: Bharathi Cherukuri | Posted on: 4/26/2012 | Category: .NET Framework Interview questions | Views: 615 | | 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 
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Bharathi Cherukuri

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 8:05:05 AM