Hi,
boolean b = false;
String s = (b=!b)?(b=!b)?"Hello":"hello"
b=!b)?"world":"World";
Terinary operators have assositivity from Right to left.
So, the above expression becomes
String s = (b=!b)?((b=!b)?"Hello":"hello")
(b=!b)?"world":"World");
So first, this executes:-((b=!b)?"world":"World")
Result is: world and boolean b = true.
Expression becomes:
String s = (b=!b)?((b=!b)?"Hello":"hello"): world
Now, (b=!b)?"Hello":"hello" executes:
Result is: hello and boolean b = false.
So expression becomes: String s = (b=!b)? "hello":"world"
Finally out put is: hello.
I hope i explained clearly.