Reputation: 392
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
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
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
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