+ 3
Can anyone help me to understand public private and protected member in class?
4 odpowiedzi
+ 5
A public member can be accessed outside of the class it's declared in
A private member on the other hand can only be accessed within the class it's declared in
A protected member can be accessed within the class its declared in or within its subclasses
Typically, most members should be set private so you can more securely access them with getter and setter functions rather than referring to a member directly from its object
+ 2
Assuming b is a subclass of a, you'll be able to access the protected member of a within b, but won't be able to access the private member
+ 1
can we access private nd protected member in class b if i declared it in class a?