Object Oriented Programming - I (3140705) MCQs

MCQs of Selections , Mathematical functions and loops

Showing 31 to 38 out of 38 Questions
31.
What will be the output of the following Java program?
    class jump_statments 
    {
        public static void main(String args[]) 
        {        
             int x = 2;
             int y = 0;
             for ( ; y < 10; ++y) 
             {
                 if (y % x == 0) 
                     continue;  
                 else if (y == 8)
                      break;
                 else
                    System.out.print(y + " ");
             }
        } 
    }
(a) 1 3 5 7
(b) 2 4 6 8
(c) 1 3 5 7 9
(d) 1 2 3 4 5 6 7 8 9
Answer:

Option (c)

32.
What will be the output of the following Java program?
    class comma_operator 
    {
        public static void main(String args[]) 
        {    
             int sum = 0;
             for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
                 sum += i;
 	     System.out.println(sum);
        } 
    }
(a) 5
(b) 6
(c) 14
(d) compilation error
Answer:

Option (b)

33.
What will be the output of the following Java program?
    class selection_statements 
    {
        public static void main(String args[])
        {
            int var1 = 5; 
            int var2 = 6;
            if ((var2 = 1) == var1)
                System.out.print(var2);
            else 
                System.out.print(++var2);
        } 
    }
(a) 1
(b) 2
(c) 3
(d) 4
Answer:

Option (b)

34.
Which of this statement is incorrect?
(a) switch statement is more efficient than a set of nested ifs
(b) two case constants in the same switch can have identical values
(c) switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression
(d) it is possible to create a nested switch statements
Answer:

Option (b)

35.
Which of these jump statements can skip processing the remainder of the code in its body for a particular iteration?
(a) break
(b) return
(c) exit
(d) continue
Answer:

Option (d)

36.
Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
(a) do-while
(b) while
(c) for
(d) none of the mentioned
Answer:

Option (a)

37.
Which of these are selection statements in Java?
(a) if()
(b) for()
(c) continue
(d) break
Answer:

Option (a)

38.
Which of these selection statements test only for equality?
(a) if
(b) switch
(c) if & switch
(d) none of the mentioned
Answer:

Option (b)

Showing 31 to 38 out of 38 Questions