Flow Control in Java MCQs

@T-Bone

This question paper focuses on the "Flow Control" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

This question paper focuses on the "Flow Control" of the Java programming. These Multiple Choice Questions (mcq) should be practiced to improve the Java programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

Questions

1. What will be the output of the following code snippet? int a=15; int b=25; if ((a < b ) || ( a = 5)>15) system.out.println(a); else system.out.println(b);

Mark the correct option

2. What will be the output of the program? int x, y; x=15; y=20; if (x>15) if(y>15) { system.ptintln("y is "+y); } else system.out.ptintln("x is "+x);

Mark the correct option

3. Which two are acceptable types for x? switch(x) { default: System.out.println("Hello"); }

Mark the correct option

4. Which statement is true? public void test(int x) { int odd = 1; if(odd) /* Line 4 */ { System.out.println("odd"); } else { System.out.println("even"); } }

Mark the correct option

5. Which statement is true? public class While { public void loop() { int x= 0; while ( 1 ) /* Line 6 */ { System.out.print("x plus one is " + (x + 1)); /* Line 8 */ } } }

Mark the correct option

6. Which of the following for loop declaration is not valid?

Mark the correct option

7. _______ is not a flow control statement in Java.

Mark the correct option

8. The break statement causes an exit from ______ loop.

Mark the correct option

9. Which of the following is an iteration statement?

Mark the correct option

10. What is the valid data type for variable "a" to print "Hello World"? switch(a) { System.out.println("Hello World"); }

Mark the correct option

11. What is the output of this program? class selection_statements { public static void main(String args[]) { int var1 = 5; int var2 = 6; if ((var2 = 1) == var1) System.out.print(var2); else System.out.print(++var2); } }

Mark the correct option

12. What is the output of this program? class comma_operator { public static void main(String args[]) { int sum = 0; for(int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1) sum += i; System.out.println(sum); } }

Mark the correct option

13. What will be the output of the program? int i = l, j = -1; switch (i) { case 0, 1: j = 1; /* Line 4 */ case 2: j = 2; default: j = 0; } System.out.println("j = " + j);

Mark the correct option

14. In the following code snippet, which lines of code contain error? int j=0; while (j < 10) { j++; if (j==5) continue loop; system.out.ptintln("j is " +j); }

Mark the correct option

15. What is the output of this program? int i = 1, j = 10; do { if(i > j) { break; } j--; } while (++i < 5); System.out.println("i = " + i + " and j = " + j);

Mark the correct option

Index of Questions