- #1
Bleys
- 74
- 0
Hello there; I have a very short question about client class access:
Suppose in a supplier class an instance variable is declared private (and is used in the constructor), and a void method in the same class (declared public) changes this variable. In the client class, is calling this method still going to change the variable (assuming an object of that class is instantiated of course). I know if the method is called within its own class then the variable will be changed, no problem. I was wondering whether the fact it's being called outside of its class makes a difference.
Something like:
public class Auto(){
private int gas;
public Auto(){
gas = 0
}
public void addGas(int g){
gas = gas + g;
}
}
and if addGas is called somewhere outside of the class, will the gas variable still be accessed and changed?
Suppose in a supplier class an instance variable is declared private (and is used in the constructor), and a void method in the same class (declared public) changes this variable. In the client class, is calling this method still going to change the variable (assuming an object of that class is instantiated of course). I know if the method is called within its own class then the variable will be changed, no problem. I was wondering whether the fact it's being called outside of its class makes a difference.
Something like:
public class Auto(){
private int gas;
public Auto(){
gas = 0
}
public void addGas(int g){
gas = gas + g;
}
}
and if addGas is called somewhere outside of the class, will the gas variable still be accessed and changed?