When do we use the protected visibility specifier to a class member?
Answers
Answered by
11
Protected variables allow access to the variables only from sub-classes and classes within the same package. Protected variables can be useful if you want your data to be read-only, or when you want to abstract your data. However, you can just use private variables with getters and setters methods.
Answered by
0
When we want a member function within a class to access a data member as well as member functions that are immediately derived from it, we use the visibility modifier protected.
what is a member functions class?
- A class's member function is a function that, like any other variable, has its definition or prototype in the class's definition.
- It has access to all members of the class for which it is a member and can operate on any object of that class.
How can another class gain access to a class's protected members?
The protected members of the class can be accessed through the parent and child classes of the class. The term "default access specifier" isn't a key phrase; it's used when no other access specifiers are specified.
#SPJ3
Similar questions