Sail E0 Webinar

MCQs

Total Questions : 42 | Page 2 of 5 pages
Question 11. Which of the following for loops will be an infinite loop?
  1.    for(; ;)
  2.    for(i=0 ; i
  3.    for(i=0; ; i++)
  4.    All of the above
 Discuss Question
Answer: Option D. -> All of the above
Question 12. 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
  1.    1 2 3 1
  2.    1 2 3 2
  3.    Repeatedly print 1 2 3 and cause infinite loop.
  4.    Compilation fails because of line 2
  5.    None of these
 Discuss Question
Answer: Option C. -> Repeatedly print 1 2 3 and cause infinite loop.
Question 13. What is the value of a[1] after the following code is executed?
int[] a = {0, 2, 4, 1, 3};
for(int i = 0; i < a.length; i++)
a[i] = a[(a[i] + 3) % a.length];
  1.    0
  2.    1
  3.    2
  4.    3
  5.    4
 Discuss Question
Answer: Option B. -> 1
Question 14. 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");
}
}
}
  1.    true
  2.    false
  3.    Compiler error
  4.    None of these
 Discuss Question
Answer: Option A. -> true
Question 15. 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;
}
}
}
  1.    0
  2.    1
  3.    2
  4.    3
  5.    1 2
 Discuss Question
Answer: Option E. -> 1 2
Question 16. What all gets printed when the following program is compiled and run?
public class Test{
public static void main(String args[]){
int i=0, j=2;
do{
i=++i;
j--;
}while(j>0);
System.out.println(i);
}
}
  1.    0
  2.    1
  3.    2
  4.    The program does not compile because of statement "i=++i;"
  5.    None of these
 Discuss Question
Answer: Option C. -> 2
Question 17. 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);
}
}
  1.    1
  2.    2
  3.    -1
  4.    0
  5.    None of these
 Discuss Question
Answer: Option D. -> 0
Question 18. 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?
  1.    int y = x;
  2.    int y = 10;
  3.    int y = 11;
  4.    int y = 12;
  5.    None of the above will allow compilation to succeed.
 Discuss Question
Answer: Option C. -> int y = 11;
Question 19. What will be the result?
1. int i = 10;
2. while(i++
  1.    10
  2.    11
  3.    12
  4.    13
  5.    Line 5 will be never reached.
 Discuss Question
Answer: Option D. -> 13
Question 20.


What will be the output of the program?


int I = 0;
label:
if (I < 2) {
System.out.print("I is " + I);
I++;
continue label;
}
  1.    I is 0
  2.    I is 0 I is 1
  3.    Compilation fails.
  4.    None of the above
 Discuss Question
Answer: Option C. -> Compilation fails.

The code will not compile because a continue statement can only occur in a looping 

construct. If this syntax were legal, the combination of the continue and the if statements 

would create a kludgey kind of loop, but the compiler will force you to write cleaner code 

than this.


Latest Videos

Latest Test Papers