0
When we declare a variable private then why Java dont allow it to access from outside the class?
Since public data members can be accessed from outside the class and private can't. So how java does this.
3 Réponses
+ 2
It is choice by design and is common in almost all programming languages that use these keywords. How the language handles it is something out of my knowledge and would let someone else answer it.
0
A private variable can be accessed through getter and setter methods which must be public. Since a private variable can be accessed within the class only, you get them inside get and set which are public a later access them from outside the class.
I have explained the access levels well in detail in the below thread.
https://www.sololearn.com/discuss/2262605/?ref=app
0
Avinesh I am not asking how they can be accessed ??
I am asking how java handles them. What java does to them so that public can be accessed from outside the class and private can't.