oop - Why protected and private attributes are accessible by same class rather than by the same object? -


for example, have class man

if man.age protected, don't see why chucknorris (instance of class man) can change protected/private attribute age of object jackbauer (another instance of class man). shouldn't able (imo).

in mind, value of protected/private attribute supposed belong object itself, not class...

i need explanation think, i'm confused.

matthieu right. cucknorris can jackbauer.age

but there no problem on that. if referencing man instance attributes inside man, means coding man class, know doing.

the problem if pass me man class , access man attributes out knowing how man class coded.

setters , getters may doing business logic don't know , don't need know. 1 coded mam know.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -