//What is the result of executing the following fragment of code:
class _2{ public static void main(String []args){ boolean flag = false; if (flag = true) { System.out.println("true"); } else { System.out.println("false"); } boolean flag1 = false; if (flag1 == true) { System.out.println("true"); } else { System.out.println("false"); } } } what is the difference bet. = and == in the argument section of the if statement? what will the answer be.?
Hi, In the first case (flag1=true) you are assinging "true" to flag1.So if condition will be always true and hence prints "TRUE". In the second case ( flag1 == true) ,here you are comparing the value of flag1 ,which is assinged to false, so if condition will be flase and hence will print "False". Correct if wrong thanx
Swati Kale
SCJP
SCWCD
Siobhan Murphy
Ranch Hand
Joined: Oct 19, 2000
Posts: 72
posted
0
reads as 'set a to b' or 'a becomes b', whereas
reads as 'Does a denote the same obect as b?' Hope this helps
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.