Ways to restrict access of base class members in derived class

Posted by Vaibhav21791 under Interview Questions on 8/29/2012 | Points: 10 | Views : 1191 | Status : [Member] | Replies : 3
hi,
By declaring base class members as private we can restrict their access in derived class,is their any other way to do the same ?




Responses

Posted by: Maheshvishnu on: 8/29/2012 [Member] Starter | Points: 25

Up
0
Down
declare class with sealed keyword

eg: sealed class Example
{
}

mahesh

Vaibhav21791, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gopesh9 on: 8/29/2012 [Member] Starter | Points: 25

Up
0
Down
Vaibhav, I think that there is no way how you can restrict their access in derived class other than declaring it private. Yeah in c++ we have that concept to give access level in deriving but i think there is no way in C#. By making the class Sealed you cannot derived it, if you want to derive and dont want to use in your derived class better give private accessiblity to the data members of that class.

G. S.
.Net Developer

Vaibhav21791, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 10/23/2012 [Member] Starter | Points: 25

Up
0
Down
hi...gopesh

you are right...we have no other way to restrict the base class members to be used in the derived class without applying the concept of private modifier.

hi Maheshvishnu.

Sealed classes are those class which are not further inherited by any class. So, it is a different scenario.


Sourabh07

Vaibhav21791, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response