Let the Java method func be defined as class TestSideEffect
Let the Java method func be defined as class TestSideEffect {int sum= 1; private int func (int i, int j) {sum++; return (i*j);} public void method(String [] args) {//test side effect System.out.printf(\"func = %d sum=%d \ \", sum + func(2, 3), sum);}} The operans in Java are evaluated left to right. What are output of this program. Explain your results.
Solution
sum+func(2,3) the value for this is the sum plus func here the sum=1 as initialized in the class and when ever the func is called the value increases and it returns 2*3 =6,the value for this first field is the sum value before increment and the func return value i.e. 1+6=7,,now the sum value is 2 because it is incremented in func method,
so the out put of this method is
func=7 sum=2
![Let the Java method func be defined as class TestSideEffect {int sum= 1; private int func (int i, int j) {sum++; return (i*j);} public void method(String [] ar Let the Java method func be defined as class TestSideEffect {int sum= 1; private int func (int i, int j) {sum++; return (i*j);} public void method(String [] ar](/WebImages/2/let-the-java-method-func-be-defined-as-class-testsideeffect-970575-1761495929-0.webp)