In Java, how can I get the cumulative total of more than one primitive variables in the calling function. I would like to use another method to do the addition. But how do I do it in Java as it passes primitive types by value?
public void methodA(){
int totalA = 0;
int totalB = 0;
Car aCar = getCar() ; //returns a car object with 2 int memebers a & b
methodB(aCar);
methodB(bCar);
methodB(cCar);
sysout(totalA); // should print the sum total of A's from aCar, bCar and cCar
sysout(totalB); // should print the sum total of b's from aCar, bCar and cCar
}
private methodB(aCar){
totalA += aCar.getA();
totalB += aCar.getB();
}