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

What is the difference between overriding and overloading in systemverilog?

988


What is marshalling and what are different kinds of marshalling?

915


Helo , Help Me , Help Me About : C# Windows Application - Network How To Manage IP Client's Accessiblity To The Internet Share concise Substitute , Minor ISA Server

1956


What will a loop recorder show?

970


Can we inherit two classes in c#?

951


Which is the base class in c#?

920


What operators can be used to cast from one reference type to another without the risk of throwing an exception?

907


what is IFormatable

991


What is multithreading with .net?

1000


What is selector c#?

903


What is callback method in c#?

935


Explain the difference between the system.array.copyto() and system.array.clone()?

926


Write the syntax for catching an exception in c#?

883


What is c# most used for?

975


Are c# constructors the same as c++ constructors?

950