Page 147 - CA_Blue( J )_Class10
P. 147

7.  In Java, instead of …………………, Ternary operator may be used.
                       a.  switch-case                                 b.  if-else
                       c.  for loop                                    d.  while loop
                    8.  The default case in the switch statement is executed only if ………………… .
                       a.  No other case matches the expression        b.  The expression is null
                       c.  The switch statement is incomplete          d.  The break statement is omitted
                    9.  Consider the following code:
                       switch(true)
                       {
                            case 1:
                                    System.out.println ("Orange");
                                  break;
                            case 2:
                                    System.out.println ("Education");
                                  break;
                            default:
                                    System.out.println("Wrong choice");
                       }
                       Which of the following is the output of the preceding code?
                       a.  Orange                                      b.  Education
                       c.  Wrong choice                                d.  Incompatible types error
                   10.  Consider the following code:
                       if(Name == "Orange Education")
                            s = "You are at right place.";
                       else
                            s = "Try again";
                       Which of the following is equivalent to the preceding code?
                       a.  s = (Name == "Orange Education") ? "You are at right place." : "Try again";
                       b.  s = (Name = "Orange Education") ? "You are at right place." : "Try again";
                       c.  s = (Name == Orange Education) ? You are at right place. : Try again;
                       d.  s = ("Orange Education") ? "You are at right place." : "Try again";
                   11.  Which of the following is correct about switch and if statements?
                       a.  The switch statement can be used inside the if statement
                       b.  The if statement can be used inside the case of the switch statement
                       c.  Both the statements are correct
                       d.  if and switch statement cannot handle multiple conditions at once.
                   12.  Which of the following boolean expressions will execute the if block?

                       int x = 5, y = 10;
                       if ( /* boolean expression */ ) {
                           System.out.println("Condition met");
                       }
                       a.  x > y                                       b.  x == y
                       c.  x < y                                       d.  x >= y
                   13.  What is the result of the following code?
                       int a = 5, b = 10;
                       String result = (a > b) ? "a is greater" : "b is greater";
                       System.out.println(result);
                       a.  a is greater                                b.  b is greater
                       c.  true                                        d.  false
                   13.  What will be the output of the following code?
                       int age = 25;
                       if (age < 18)

                                                                                                                       145
                                                                                           Conditional Constructs in Java  145
   142   143   144   145   146   147   148   149   150   151   152