Jaroslav Sedlacek

+ Follow
since Dec 31, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jaroslav Sedlacek

Hi Akbar,

thanks for nice riddle.

IMHO the example is combination of both - operator precedence and evaluation of boolean expressions.

Because && has really higher priority than ||, expression is evaluated the same way as:

boolean x = (a = true) || ( (b = true) && (c = true) );

And now evaluation of boolean expressions takes its part. Because left expression is true, rest is not evaluated.

So the result is: true, false, false
To be more accurate:

Only non-static methods can be overriden.
Just one note: In case of Java 5.0 it compiles fine because of autoboxing.
I agree with Marc, except one thing:

So the only way I can see that a value of 200 would be printed rather than 100 is if the thread scheduler gave the main thread a chance to run immediately after setting bContinue to true, but before entering the infinite loop. This seems doubtful, but I suppose it's possible.

As he wrote earlier run method is synchronized. It obtains lock before it sets bContinue to true and it still owns it even when thread scheduler gave the main thread a chance to run.