Sail E0 Webinar

MCQs

Total Questions : 19 | Page 2 of 2 pages
Question 11. Which of the following for loops will be an infinite loop?
  1.    All of these
  2.    for(; ;)
  3.    for(i=0; ; i++)
  4.    for(i=0 ; i
 Discuss Question
Answer: Option A. -> All of these
Question 12. 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.    2
  2.    0
  3.    3
  4.    1
  5.    4
 Discuss Question
Answer: Option D. -> 1
Question 13. 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.    false
  2.    Compiler error
  3.    None of these
  4.    true
 Discuss Question
Answer: Option D. -> true
Question 14. 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.    Repeatedly print 1 2 3 and cause infinite loop.
  2.    Compilation fails because of line 2
  3.    1 2 3 2
  4.    1 2 3 1
  5.    None of these
 Discuss Question
Answer: Option A. -> Repeatedly print 1 2 3 and cause infinite loop.
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.    2
  2.    1 2
  3.    0
  4.    3
  5.    1
 Discuss Question
Answer: Option B. -> 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.    2
  3.    1
  4.    None of these
  5.    The program does not compile because of statement "i=++i;"
 Discuss Question
Answer: Option B. -> 2
Question 17. What will be the result?1. int i = 10;2. while(i++
  1.    11
  2.    10
  3.    12
  4.    Line 5 will be never reached.
  5.    13
 Discuss Question
Answer: Option E. -> 13
Question 18. 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.    -1
  3.    None of these
  4.    2
  5.    0
 Discuss Question
Answer: Option E. -> 0
Question 19. 1. public class Test{2. public static void main(String [] args){3. int x = 0;4. // insert code here5. do{ } while(x++ < y);6. System.out.println(x);7. }8. }Which option, inserted at line 4, produces the output 12?
  1.    int y = 10;
  2.    int y = 11;
  3.    int y = x;
  4.    None of these
  5.    int y = 12;
 Discuss Question
Answer: Option B. -> int y = 11;

Latest Videos

Latest Test Papers