Why do we declare Private variables in Java?

前端 未结 3 541
北海茫月
北海茫月 2020-12-18 06:37

I\'m confused because all I keep hearing is that private variables in Java are supposed to protect the code or the variable. But if anybody has access to the code, then it m

3条回答
  •  天命终不由人
    2020-12-18 07:36

    why are variables private in java

    To achieve encapsulation and this can't be accessible outside the class. This doesn't mean programmer can't change the source code.

提交回复
热议问题