|
There are several basic access modifiers Public – “public, accessible to everyone.” Default – “by default”. modifier. Information with this word is available within the package. Protected - “protected”. It is similar to default, but differs in that its descendant classes also have access. Private – “private, personal”. This information is visible only to the class itself.
We are giving a discount of on training “Java Programmer” until March In just Bulgaria Email List months you can get a job with an income of , rubles Book a discount How is the safety principle ensured? It is possible to easily change this variable and string, which is not entirely good, since anyone can do this from any part of the program. If we don't need this, we change the modifier from public to private class MyClass { private String s "Hello World!" } class MyClass { private String s "Hello World!" } In this case, when trying to access variable s (read or write), an error will occur.
In this way, we managed to protect the variable from ill-wishers. The most important thing is that we manage to control what is happening. Now no one has the ability to change or read our variables. Encapsulation in Python The Python system provides three-level access to data public (public, no special syntax, publicBanana) protected (protected, highlighted by a single underscore at the beginning of the name, protectedBanana) private (private, highlighted by a double underscore at the beginning of the name, privateBanana).
|
|