System.out.println("This my first out put "+x==null?y:z); will run as
("This my first out put "+x)==null?y:z , which will never be true. Thus, it will display the value of z .
For example:
int x=10; int y=20; System.out.println(" "+x+y);
In the above scenario, the operation is performed from left to right .
As you said, you expect this:
This my first output 10
To do this, you need to slightly modify the code. try it
System.out.println("This my first output " + ((x == null) ? y : z));
Ravi
source share