1.
What will be the output of the following Java program? public class Test { public static void main(String[] args) { int i = 5; switch (i) { default: System.out.println("Default case"); case 5: System.out.println("Case 5"); case 10: System.out.println("Case 10"); } } }
2.
What will be the output of the following code? public class Test { public static void main(String[] args) { int x = 5; System.out.println(x > 2 ? x < 4 ? 10 : 8 : 7); } }
3.
What will be the output of the following Java program? public class Test { public static void main(String[] args) { for (int i = 1; i
4.
: What will be the output of the following program? public class Test { public static void main(String[] args) { int a = 2, b = 5; a = a ^ b; b = a ^ b; a = a ^ b; System.out.println("a: " + a + ", b: " + b); } }
5.
What will be the output of the following Java code? public class Test { public static void main(String[] args) { String str1 = "Java"; String str2 = new String("Java"); System.out.println(str1 == str2); System.out.println(str1.equals(str2)); } }
6.
What will be the output of this Java program? public class Test { public static void main(String[] args) { String s1 = "Java"; String s2 = "Java"; String s3 = new String("Java"); System.out.println(s1 == s2); System.out.println(s1 == s3); } }
7.
What will be the output of this Java program? public class Test { public static void main(String[] args) { int x = 10; int y = x++ + ++x; System.out.println("x: " + x + ", y: " + y); } }
8.
What will be the output of this Java program? public class Test { public static void main(String[] args) { int i = 1; while (i
9.
What will be the output of the following Java program? public class Test { public static void main(String[] args) { int arr[] = {10, 20, 30, 40, 50}; for (int i : arr) { System.out.print(i + " "); if (i == 30) break; } } }
10.
What will be the output of this Java program? java CopyEdit public class Test { public static void main(String[] args) { int i = 0; for (System.out.println("Start"); i < 3; i++) { System.out.println(i); } } }
11.
What will be the output of this Java program? public class Test { public static void main(String[] args) { int arr[] = {1, 2, 3, 4, 5}; System.out.println(arr.length); } }
12.
What will be the output of the following code? public class Test { public static void main(String[] args) { int x = 3; System.out.println((x > 2) ? ((x < 4) ? 10 : 20) : 30); } }
13.
What will be the output of this Java program? public class Test { public static void main(String[] args) { int i = 1; while (i < 5) { if (i == 3) break; System.out.print(i + " "); i++; } } }
14.
What will be the output of the following Java code? public class Test { public static void main(String[] args) { int a = 10; a += (a++) + (++a); System.out.println(a); } }
15.
What will be the output of the following program? public class Test { public static void main(String[] args) { int a = 5, b = 2; System.out.println(a / b); System.out.println(a / 2.0); } }
16.
What will be the output of the following Java program? public class Test { public static void main(String[] args) { int x = 5, y = 10; System.out.println((x > y) ? x : y); } }
17.
Predict the output of the following Java code. public class Test { public static void main(String[] args) { int x = 2; System.out.println(x++ + ++x); } }
18.
What will be the output of the following Java program? public class Test { public static void main(String[] args) { int x = 5; System.out.println(++x - x--); } }
19.
What will be the output of the following code? public class Test { public static void main(String[] args) { int a = 5, b = 10, c; c = ++a * b--; System.out.println("a: " + a + ", b: " + b + ", c: " + c); } }
20.
What will be the output of the following code? public class Test { public static void main(String[] args) { int x = 5; x = x++ * 2 + 3; System.out.println(x); } }
21.
What will be the output of this Java program? public class Test { public static void main(String[] args) { int i = 0; do { System.out.print(i + " "); i++; } while (i < 3); } }
22.
What will be the output of the following Java program? public class Test { public static void main(String[] args) { System.out.println(5 + 2 + "Hello" + 5 + 2); } }
23.
What will be the output of the following Java program? public class Test { public static void main(String[] args) { int arr[] = {1, 2, 3, 4, 5}; for (int i = 0; i < arr.length; i++) { arr[i] = arr[i] * 2; } System.out.println(arr[2]); } }
24.
What will be the output of this Java program? public class Test { public static void main(String[] args) { int i = 1; while (i
25.
What will be the output of the following Java program? public class Test { public static void main(String[] args) { int a = 5, b = 10, c = 15; System.out.println(a < b && b b || b < c); } }