054.
Line 4 compiles file since the expression iValue==5 evaluates
to a boolean value.
What would be the output if boolA is false and boolB is
true?
public void foo( boolean boolA, boolean boolB) /* Line 1
*/
{
if(boolA ) {/* Line 3 */
System.out.println(“X”); /* Line 5 */
}
else if(boolA && boolB) {/* Line 7 */
System.out.println( “X && Y”); /* Line 9 */
}
else { /* Line 11 */
if (!boolB ){ /* Line 13 */
System.out.println( “notY”); /* Line 15 */
}
else{ /* Line 17 */
System.out.println( “In here” ); /* Line 19 */
}
}
}
Answer:
Output: In here
Since boolA is false, line 5
will never execute and X will not be
printed. Since boolA is false line 7
will also not execute and so X
&& Y will also not be printed. The else block at line 11 will be
entered.
Since boolB is true, the if statement at line 13 is not
055.
executed. So, the else statement at line 13
is executed which
prints In here.
What will be the output of the following program?
public class SwitchDemo
{
final static short caseVal = 2;
public static void main(String [] abc)
{
for (int iterNo=0; iterNo < 3; iterNo ++) {
switch (iterNo) {
case caseVal– System.out.print(“a “);
case caseVal–1– System.out.print(“b “);
case caseVal–2– System.out.print(“c “);
}
}
}
}
Do'stlaringiz bilan baham: