Marc K
Marc K

Reputation: 392

Opposite of private access modifier

Is it at all possible to create a member which would effectively be inaccessible by the class that declares it? Only derived classes would be able to access the member.

Upvotes: 2

Views: 261

Answers (4)

Qash
Qash

Reputation: 167

If you really want to do that you can create a property with the set that does not allow any change - so not really inaccessible, but restricting functionality. However, this could point to design that needs revisting to decide if there is a better approach.

Upvotes: 0

Patrick
Patrick

Reputation: 1837

The closest you'd be looking for is protected, which can only be accessed by the class that declares it and its derivatives. See here: http://msdn.microsoft.com/en-us/library/ms173121.aspx

Unless you are referring to an abstract class, which can't be instantiated and can contain method declarations without code: http://msdn.microsoft.com/en-us/library/sf985hc5(v=vs.71).aspx

Upvotes: 4

Mr.V.
Mr.V.

Reputation: 128

No. In C# there's no way to do it.

Upvotes: 2

Habib
Habib

Reputation: 223402

No, that can't be done. The least access modifier is private which is accessible inside the class but not outside

Upvotes: 2

Related Questions