Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Shavkat Juraev

Greenhorn
+ Follow
since Nov 21, 2017
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shavkat Juraev

Jeanne,

Thank you for giving me credit.
I updated my name here, is it possible to update it on errata page as well?
Sorry for inconvenience.
Question 13.
3:    int x1 = 50, x2 = 75;        // According to answers on p.338, variable b is assigned true on line 3

4:    boolean b = x1 >= x2;
5:    if (b = true) System.out.println("Success");
6:    else      System.out.println("Failure");

Answer explanation: A. The code compiles successfully, so options C and D are incorrect. The value of b
after line 4 is false. However, the if-then statement on line 5 contains an assignment,
not a comparison. The variable b is assigned true on line 3, and the assignment operator
returns true, so line 5 executes and displays Success, so the answer is option A.

My confusion: How is b assigned true on line 3? How does b relate to line 3?