0

Are there any risks involved with using the protected member access specifier instead of the private member access specifier?

vixir
  • 1
  • 1
  • 2
  • You can refer the http://stackoverflow.com/questions/5447498/what-are-access-specifiers-should-i-inherit-with-private-protected-or-public. Hope it should helpful for you. – Jebasuthan Aug 06 '14 at 17:55

2 Answers2

0

You have not specified which lamguage but, I assume in OO language like java, a protected member is "visible" to child classes. Latter can use them and may break if you happen to change protected members later due to evolution of your class or change in requirements. No such risk in case of private members. A child class can extend the protected members and make it exposed to the outside (public) world.

Bimalesh Jha
  • 1,464
  • 9
  • 17
0

This answer assumes you are using a language like java:

private members can only be seen by its own class (and inner classes). This is the safest field visibility since it is hidden from all outsiders. Since it's completely hidden, you are free to change the implementation details or even get rid of the field completely later on.

protected members can not only be seen by all subclasses but also from ALL classes that are in the same package. This makes it much harder to later change the field because more classes might be referencing it.

dkatzel
  • 31,188
  • 3
  • 63
  • 67