Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Conditional Constructs in Java

Chapter 8

Conditional Constructs in Java

Class 8 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Multiple Choice Questions


Question 1

Which of the following are conditional constructs?

  1. if-else
  2. if-else-if ladder
  3. switch statement
  4. All of these ✔

Question 2

Which operator cannot be used with if-else statement?

  1. <=
  2. ||
  3. &&
  4. ? : ✔

Question 3

What will be the output of the following code?

int size = 2;

if (size < 0)

    System.out.println("Small");

else if (size == 0)

    System.out.println("Medium");

else

    System.out.printIn("Large");

  1. Small
  2. Large ✔
  3. Medium
  4. Runtime error

Question 4

What will be the output of the following code?

int fruit = 3;

switch (fruit + 1)

{

    case 1:

        System.out.println("Banana");

        break ;

    case 2:

        System.out.println("Apple");

        break ;

    case 3:

        System.out.println("Orange");

        break ;

    default :

        System.out.println("Fruitless");

}

  1. Orange
  2. Banana
  3. Apple
  4. Fruitless ✔

Question 5

Predict the output of the following code snippet:

int a = 1;

int b = 2;

if (a == b)

   System.out.println ("Both values are equal");

else

   System.out.println ("Values are not equal");

  1. Both values are equal
  2. Incorrect use of the == operator
  3. Values are not equal ✔
  4. No output

Question 6

Consider the following code snippet:

if ( c > d)

   x = c;

else

   x = d;

Choose the correct option if the code mentioned above is rewritten using the ternary operator:

  1. x = (c >d) ? c : d; ✔
  2. x = (c >d) ? d : c;
  3. x = (c >d) ? c : c;
  4. x = (c >d) ? d : d;

Question 7

if ((a > b) && (a > c)), then which of the following statements is true?

  1. a is the largest number. ✔
  2. b is the largest number.
  3. c is the largest number.
  4. b is the smallest number.

Question 8

Consider the following code snippet:

int val = 2;

switch (val)

{

   case 1: System.out.println("Case 1");

   break;

   case 2: System.out.println("Case 2");

   break;

   default: System.out.println("No match found");

   break;

}

Which of the following statements is correct?

  1. case 1 will be executed.
  2. case 2 will be executed. ✔
  3. default will be executed.
  4. both case 1 and 2 will be executed.

Question 9

A sequence of statements enclosed between a pair of curly brackets is called

  1. a compound statement ✔
  2. an empty statement
  3. a null statement
  4. a void statement

Question 10

Which clause is optional in the switch statement?

  1. default ✔
  2. case
  3. switch
  4. None of these

Question 11

Which of the following statements involves a fall-through?

  1. if-else
  2. for loop
  3. if-else-if ladder
  4. switch ✔

Question 12

Which of the following causes a fall-through in the switch statement?

  1. the omission of fall
  2. the omission of continue
  3. the omission of break ✔
  4. the omission of loop

Question 13

Which of the following is mandatory in the switch statement?

  1. break
  2. continue
  3. case ✔
  4. default

Question 14

Which of the following statement is a valid combination?

  1. if inside switch ✔
  2. switch inside if ✔
  3. else inside switch
  4. default inside if