+ 1

Is access modifire important in Java?

23rd Dec 2020, 12:47 AM
Name
Name - avatar
4 Respuestas
+ 3
"These types of modifiers are closely related to an important part of Object Oriented Programming called encapsulation. As a reminder, encapsulation is an idea that links data with the code that manipulates it. By controlling access, you can prevent misuse. For example, by making sure that certain variables can only be accessed through well-defined methods (the typical get/set combination of methods) we make sure that we won't encounter any unexpected values or deny outside access to certain variables/methods altogether" As per this article: https://stackabuse.com/access-modifiers-in-java/
23rd Dec 2020, 1:20 AM
Kevin ★
+ 2
Sometimes. They set how visible certain code is. You should expose to the user (yourself, another programmer, etc) only what they need. Other info should remain as a hidden implementation detail, there might be no way to misuse it, but we do not want (and should not) add that noise anyway.
23rd Dec 2020, 4:42 AM
Kevin ★
+ 2
Yes it is.
23rd Dec 2020, 7:11 AM
Sonic
Sonic - avatar
+ 1
That means they are used for preventing misuse of data?
23rd Dec 2020, 1:26 AM
Name
Name - avatar