WilliamKF
WilliamKF

Reputation: 43199

In C# how do I declare a base class as being private?

I know how to do this in C++:

class myClass : public baseClass1 private baseClass2 ...

How do I do likewise in C#?

This is what I have so far in C#

public class myClass : baseClass1, baseClass2

How do I specify that baseClass2 is private?

Upvotes: 1

Views: 208

Answers (4)

Jollymorphic
Jollymorphic

Reputation: 3530

Use "has-a" (aggregation) instead of "is-a" (inheritance). Qualify calls to the desired class with the member name.

Upvotes: 0

Jeremy Sylvis
Jeremy Sylvis

Reputation: 46

When you have a class inheriting other classes you have no means of specifying access - shouldn't need to. The inherited members/properties/methods have the same access level as specified in the base class.

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 191037

C# does not have multiple inheritance. What you could do is a composite with baseClass2.

Upvotes: 5

Bala R
Bala R

Reputation: 109017

C# does not support multiple inheritance and it does not support private inheritance either.

Upvotes: 10

Related Questions