Flow Control - Programming

Q1:

What will be the output of the program?
boolean bool = true; 
if(bool = false) /* Line 2 */
{
    System.out.println('a'); 
} 
else if(bool) /* Line 6 */
{
    System.out.println('b'); 
} 
else if(!bool) /* Line 10 */
{
    System.out.println('c'); /* Line 12 */
} 
else 
{
    System.out.println('d'); 
}

A a

B b

C c

D d

ANS:A - a

Look closely at line 2, is this an equality check (==) or an assignment (=). The condition at line 2 evaluates to false and also assigns false to bool. bool is now false so the condition at line 6 is not true. The condition at line 10 checks to see if bool is not true ( if !(bool == true) ), it isn't so line 12 is executed.