I don’t know which way is preferable:
- using a private method that uses a return statement which is used inside another method of the same class:
private int calculate(int x)
{
// random calculation
return x * x;
}
public void print()
{
System.out.println(calculate(3));
}
- changing the value of a private attribute which is used inside another method of the same class:
private int result;
private void calculate(int x)
{
// random calculation
result = x * x;
}
public void print()
{
System.out.println(result);
}