decision constructs

Quiz Guidelines

 

Multiple Choice Question

QID: 
332

What is the result of executing the following fragment of code:

boolean b1 = false;
boolean b2 = false;
if (b2 = b1 != b2){
System.out.println("true");
} else{
System.out.println("false");
}

Select 1 option

A. Compile time error.
B. It will print true;
C. It will print false;
D. Runtime error.
E. It will print nothing.

Multiple Choice Question

QID: 
331

Given:

enum Season { SUMMER, WINTER, SPRING, FALL }

What will the following code print?

Season s = Season.SPRING;
switch(s){
case SUMMER : System.out.println("SUMMER");
case default : System.out.println("SEASON");
case WINTER : System.out.println("WINTER");
}

Select 1 option

A. SEASON
B. SEASON
WINTER
C. It will not compile.
D. It will not print anything.

Multiple Choice Question

QID: 
330

What is the result of executing the following fragment of code:

boolean b1 = false;
boolean b2 = false;
if (b2 = b1 == false){
System.out.println("true");
} else{
System.out.println("false");
}

Select 1 option

A. Compile time error.
B. It will print true
C. It will print false
D. Runtime error.
E. It will print nothing.

Multiple Choice Question

QID: 
329

What, if anything, is wrong with the following code?

void test(int x){
switch(x){
case 1:
case 2:
case 0:
default :
case 4:
}
}

Select 1 option

A. Data Type of 'x' is not valid to be used as an expression for the switch clause.
B. The case label 0 must precede case label 1.
C. Each case section must end with a break keyword.
D. The default label must be the last label in the switch statement.
E. There is nothing wrong with the code.

Multiple Choice Question

QID: 
328

What will the following program print?

public class TestClass{
public static void main(String[] args){
Object obj1 = new Object();
Object obj2 = obj1;
if( obj1.equals(obj2) ) System.out.println("true");
else System.out.println("false");
}
}

Select 1 option

A. true
B. false
C. It will not compile.
D. It will compile but throw an exception at run time.
E. None of the above.

Pages