This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dans o/p" Watch "Dans o/p" New topic
Author

Dans o/p

sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257

Answer is b. Can someone explain why?
Thanks


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,
Corey


SCJP Tipline, etc.
sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
Thanks Corey
 
Consider Paul's rocket mass heater.
 
subject: Dans o/p
 
Similar Threads
Ternary Operator
Oerator precedence
A Dan Mock Exam Question (Dec 4)
doubt in explanation dam mock question
Operator Precedence