Object Oriented Programming - I (3140705) MCQs

MCQs of Selections , Mathematical functions and loops

Showing 11 to 20 out of 38 Questions
11.
In java, ............ can only test for equality, where as .......... can evaluate any type of the Boolean expression.
(a) switch, if
(b) if, switch
(c) if, break
(d) continue, if
Answer:

Option (a)

12.
Which of the following for loops will be an infinite loop?
(a) for (;;)
(b) for (i=0;i<1;i--)
(c) for(i=0;;i++)
(d) All of the above
Answer:

Option (d)

13.
Determine output:
public class Test{
        public static void main(String args[]){
                int i; 
                for(i = 1; i < 6; i++){ 
                        if(i > 3) continue ; 
                }
                System.out.println(i); 
        }
}
(a) 2
(b) 3
(c) 4
(d) 6
Answer:

Option (d)

14.
Consider the following program written in Java.
class Test{
        public static void main(String args[]){
                int x=7; 
                if(x==2); 
                System.out.println("NumberSeven");
                System.out.println("NotSeven");
        }
}
What would the output of the program be?
(a) NumberSeven NotSeven
(b) NumberSeven
(c) NotSeven
(d) Error
Answer:

Option (a)

15.
Determine output:
public class Test{
        public static void main(String args[]){
                int i, j;
                for(i=1, j=0;i<10;i++) j += i;
                System.out.println(i);
        }
}
(a) 10
(b) 11
(c) 9
(d) 20
Answer:

Option (a)

16.
What will be the value of y after execution of switch statement?
public class Test{
        public static void main(String[] args){
                int x = 3, y = 4;
                switch(x + 3){
                        case 6: y = 0;
                        case 7: y = 1;
                        default: y += 1;
                }
        }
}
(a) 1
(b) 2
(c) 3
(d) 4
Answer:

Option (b)

17.
What is the printout of the following switch statement?
char ch = 'a';  
switch (ch){
      case 'a':
      case 'A': System.out.print(ch); break;
      case 'b':
      case 'B': System.out.print(ch); break;
      case 'c':
      case 'C': System.out.print(ch); break;
      case 'd':
      case 'D': System.out.print(ch);
}
(a) abcd
(b) aa
(c) a
(d) ab
Answer:

Option (c)

18.
How many times will the following code print "Welcome to DIET"?
int count = 0;
do {
      System.out.println("Welcome to DIET");
      count++;
} while (count < 10);
(a) 8
(b) 9
(c) 10
(d) 11
Answer:

Option (c)

19.
What will be the result of the following code?
public class Test{
      static public void main(String args[]){ //line 2
            int i, j;
            for(i=0; i<3; i++){
                  for(j=1; j<4; j++){
                        i%=j;
			System.out.println(j);
		  }
	    }
      }
}
(a) 1 2 3 1
(b) 1 2 3 2
(c) Repeatedly print 1 2 3 and cause infinite loop.
(d) Compilation fails because of line 2
Answer:

Option (c)

20.
What all gets printed when the following program is compiled and run.
public class Test{
      public static void main(String args[]){ 
            int i, j=1;
            i = (j>1)?2:1;
            switch(i){
                  case 0: System.out.println(0); break;
                  case 1: System.out.println(1);
                  case 2: System.out.println(2); break;
                  case 3: System.out.println(3); break;
            }
      }
}
(a) 0
(b) 1
(c) 2
(d) 1 2
Answer:

Option (d)

Showing 11 to 20 out of 38 Questions