Can we inherit a private class into the public class?

 Posted by Poster on 5/8/2010 | Category: C# Interview questions | Views: 8968
Answer:

No, In C#, a derived class can’t be more accessible than it’s base class. It means that you can't inherit a private class into a public class. So always the base class should be more or equal accessible than a derived class.

// Following will throw compilation error
private class BaseClass

{
}
public class DerivedClass : BaseClass
{
}


// Following will compile without an error
public class BaseClass

{
}
public class DerivedClass : BaseClass
{
}


Hope this helps


| Alert Moderator 

Comments or Responses

Login to post response