Object Oriented Programming - I (3140705) MCQs

MCQs of Selections , Mathematical functions and loops

Showing 21 to 30 out of 38 Questions
21.
What will be the output?
public class Test{
      public static void main(String args[]){ 
            int i = 1;
            do{
                  i--;
            }while(i > 2);
            System.out.println(i);
      }
}
(a) 1
(b) 2
(c) -1
(d) 0
Answer:

Option (d)

22.
What will be the result?
  int i = 10;
  while(i++ <= 10){
        i++;
  }
  System.out.print(i);
(a) 10
(b) 11
(c) 12
(d) 13
Answer:

Option (d)

23.
What will be the result of compiling and runnig the following code:
public class Test{
      public static void main(String... args) throws Exception{
            Integer i = 34;
            int l = 34;
            if(i.equals(l)){
                  System.out.println("true");
            }else{
                  System.out.println("false");
            }
      }
}
(a) true
(b) false
(c) Compiler error
(d) None of these
Answer:

Option (a)

24.
1. public class Test{
2.       public static void main(String [] args){
3.             int x = 0;
4.             // insert code here
5.             do{ } while(x++ < y);
6.             System.out.println(x);
7.       }
8. }
Which option, inserted at line 4, produces the output 12?
(a) int y = x;
(b) int y = 10;
(c) int y = 11;
(d) int y = 12;
Answer:

Option (c)

25.
What will be the result?
1.  int i = 10;
2.  while(i++ <= 10){
3.        i++;
4.  }
5.  System.out.print(i);
(a) Line 5 will be never reached.
(b) 11
(c) 12
(d) 13
Answer:

Option (d)

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
Answer:

Option (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
Answer:

Option (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
Answer:

Option (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
Answer:

Option (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
                                
(a) Hello
(b) run time error
(c) Hello world
(d) compile time error
Answer:

Option (d)

Showing 21 to 30 out of 38 Questions