In OOP, for example, you need to put something Private. I know that any private member cannot be accessed, but with the same class objects. But why should I do this while I'm the only encoder of my project. The same question applies to Protectedwho!
Private
Protected
privateand protecteddo not exist, that other coders could not get access to the internal elements of the class, but (also) to prevent the creation of programs without clearly defined interfaces.
private
protected
If every class in your project can modify every other class, you are not only error prone due to the huge state space, but you are also hindering yourself:
:
, , .
.
, .
, , , , , .
"" . "" , , . , .. , , , , python. , (!) , . , . . . , , .
private, . , , , , . (). Car, , Car, , , , Car Car, , , Car, , . private, , .
Car
, protected ( Java, ) , , , . , , , .
: , , , (private), , , , () , , ().
private protected . . , :
- . , . , . . , . . , . ( )
Note. The answers are good, and this answer is to complete them.
If you define a member (variable or method) of a class as private, you cannot use it externally using another class using the point operator. Protected helps protect a member variable or method from inheritance.