Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I download a program to my desktop?

836


How many static constructors are allowed in a class?

861


Which debugging tools you can use in the .NET ssSDK?

932


Define interface class in c#?

839


What is the difference between the debug class and trace class? Documentation looks the same.

1047


What is a datacontract?

861


What is the difference between a method and a property?

941


What is the c# equivalent of c++ catch (...), Which was a catch-all statement for any possible exception?

940


What is c# in asp net?

873


How do you serialize an object?

959


Which constructor is called first in c#?

881


Can we inherit private class in c#?

885


What is ispostback c#?

822


Why dictionary is faster than list?

905


What is an abstract class c#?

841