Page 1 of 1

About Question enthuware.ocpjp.i.v11.2.1290 :

Posted: Tue Jun 30, 2020 12:32 pm
by rashadat
Consider the following method:

static int mx(int s){
for(int i=0; i<3; i++){
s = s + i;
}
return s;
}

and the following code snippet:

int s = 5;
s += s + mx(s) + ++s;
System.out.println(s);

What will it print?


EXPLANATION:

s += (expression) will be converted to s =  s + expression. So the given expression will become:
s = s + s + mx(s) + ++s;
s = 5 + 5 + mx(5) + 6;
s = 5 + 5+ 8 + 6;
s = 24;


My Question: Where come from 8?

Re: About Question enthuware.ocpjp.i.v11.2.1290 :

Posted: Tue Jun 30, 2020 12:45 pm
by admin
8 is the value returned by the method invocation mx(5).