Java - MCQ

Multiple Choice Questions


Share with a Friend

 

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

26. What is true about do statement?
A). do statement executes the code of a loop at least once
B). do statement does not get execute if condition is not matched in the first iteration
C). do statement checks the condition at the beginning of the loop
D). do statement executes the code more than once always
View Answer
Correct: A



27. What is true about a break?
A). Break stops the execution of entire program
B). Break halts the execution and forces the control out of the loop
C). Break forces the control out of the loop and starts the execution of next iteration
D). Break halts the execution of the loop for certain time frame
View Answer
Correct: B



28. What would be the output of the following code snippet if variable a=10?

if(a<=0)
{
   if(a==0)
   {
     System.out.println("1 ");
   }
   else 
   { 
      System.out.println("2 ");
   }
}
System.out.println("3 ");
A). 1 2
B). 2 3
C). 1 3
D). 3
View Answer
Correct: D



29. What will be the output of the following Java program?

    class Output 
    {
        public static void main(String args[]) 
        {    
             int a = 5;
             int b = 10;
             first: 
             {
                second: 
                {
                   third: 
                   { 
                       if (a ==  b >> 1)
                           break second;
                   }
                   System.out.println(a);
                }
                System.out.println(b);
             }
        } 
    }
A). 5 10
B). 10 5
C). 5
D). 10
View Answer
Correct: D



30. What will be the output of the following Java program?

class Output 
{
        public static void main(String args[]) 
        {    
           final int a=10,b=20;
          while (a<="" pre="" style="box-sizing: border-box;">

A). Hello
B). run time error
C). Hello world
D). compile time error
View Answer
Correct: D



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper