+10

Is PHP the only language where protected members are accessible by parent classes?

Most other languages that use the protected accessibility keyword only makes such members accessible to the class and subclasses.

4/17/2019 11:53:29 PM

Sonic

8 Answers

New Answer

+16

Members declared protected can be accessed only within the class itself and by inherited and parent classes.

+15

Sonic its right for most of the languages like java

+4

Elva but in C++ protected members are only accessible within the class and it's subclasses but not within parent classes.

+4

Elva I am not talking about protected inheritance. I am just talking about visibility of protected members in a parent class of the class that contains the protected members. PHP seems to have this but I don't know of any other language that does.

+3

Roma yes that's right for PHP but is parent accessibility of protected members only a feature of PHP or are there other languages where parent classes have visibility of protected members of a child class?

+2

In c++ there are 3 types of inheritance, and one of them inherits protected as well Java inherits protected CORRECTION c++, all 3 types inherit protected, but only in one type they turn into private properties https://stackoverflow.com/questions/860339

+2

I'm sorry but visibility of child properties in parent class is something I hear of for the first time

+1

Aaaaaa you want reverse inheritance, like super class inherits from child class... I hear that for the first time