File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dans o/p Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dans o/p" Watch "Dans o/p" New topic

Dans o/p

sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257

Answer is b. Can someone explain why?

Sunita<br />SCJP 1.4
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
When this line executes:
i = i++ + m(i);
the operands are evaluated from left to right. First, the left hand operand is evaluated:
i = 0, so the equation becomes
i = 0 + m(i);
However, as we're using a post-increment operator, we now increment i to 1. Now we evaluate the next operand, m(i), by sending 1 to that method.
That results in the number 1 being printed, followed by a comma. Also, that method returns a 0, so our original formula evaluates to:
i = 0 + 0;
Therefore, the answer is: 1,0
I hope that helps,

SCJP Tipline, etc.
sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
Thanks Corey
I agree. Here's the link:
subject: Dans o/p
It's not a secret anymore!