Object Oriented Programming: Unit II: Inheritance, Packages and Interfaces

What is Protected Member?

Object Oriented Programming

The protected mode allows accessing the members to all the classes and subclasses in the same package as well as to the subclasses in other package. But the non subclasses in other package can not access the protected members.

What is Protected Member?

• Protected mode is another access specifier which is used in inheritance.

• The protected mode allows accessing the members to all the classes and subclasses in the same package as well as to the subclasses in other package. But the non subclasses in other package can not access the protected members.

• For example, if some variable is declared as protected, then the class itself can access it, its subclass can access it, and any class in the same package can also access it.

• Similarly if the variable is declared as private then that variable is accessible by that class only and its subclass or package can not access it.

Object Oriented Programming: Unit II: Inheritance, Packages and Interfaces : Tag: : Object Oriented Programming - What is Protected Member?