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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
rashadat
Posts: 1
Joined: Tue Jun 30, 2020 12:19 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

8 is the value returned by the method invocation mx(5).

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests