Question 737: public void foo( boolean a, boolean b) { if( a ) { System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ { System.out.println( "A && B"); } else /* Line 11 */ { if ( !b ) { System.out.println( "notB") ; } else { System.out.println( "ELSE" ) ; } } }
tcs
wipro
infosys
general
aptitude
flow-control
java-programming
Option C is correct. The output is "ELSE". Only when a is false do the output lines after 11 get some chance of executing.Option A is wrong. The output is "A". Whenais true, irrespective of the value ofb, only the line 5 output will be executed. The condition at line 7 will never be evaluated (when a is true it will always be trapped by the line 12 condition) therefore the output will never be "A && B".Option B is wrong. The output is "A". Whenais true, irrespective of the value ofb, only the line 5 output will be executed.Option D is wrong. The output is "notB".