0
How can i private instance variable of a class can be accessed by its object?
private variables cannot be accessed by any other class and objects ..right? https://code.sololearn.com/czfaKE3MZFSr/?ref=app
5 Respostas
+ 1
You use getter and setter methods
+ 1
like:
public String getName(){
return private_Name;
}
+ 1
@Limitless ..hehhe..i got that buddy..but im trying to understand the importance of private access modifier
0
When you want to get for example your IP address from your computer, the class that controls it will only allow you to GET it, and not SET it.
It is there to help the whole program work as it should. Instead of allowing the Programmer to change their IP address, it only allows them to view it.
I hope you understand the example.
There are other examples as well. Like get current time.