Flow Control

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.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.