Java - MCQ

Multiple Choice Questions


Share with a Friend

 

Java MCQ - Loops, Decisions and Mathematical functions - Set 26

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
View Answer
Correct: 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
View Answer
Correct: 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
View Answer
Correct: 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
View Answer
Correct: 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
View Answer
Correct: D



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper