Explore topic-wise MCQs in Java Programming.

This section includes 4 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?public class dynamic_initialize { public static void main(String args[]) { double p, q; p = 4.5; q = 10.0; double r = Math.sqrt(p * p + q * q); System.out.println(r); } }

A. 11.965
B. 10.965
C. 10.965856099730654
D. 12.965
E. 10.865856099730654
Answer» D. 12.965
2.

What is the output of this program?public class scope_var { public static void main(String args[]) { int a; a = 5; { int b = 6; System.out.print(a + " " + b); } System.out.println(a + " " + b); } }

A. Compilation error
B. 5 6 5 6
C. 5 6 5
D. Runtime error
E. None of these
Answer» B. 5 6 5 6
3.

What is the output of this program?public class arr_var { public static void main(String args[]) { int array_var [] = new int[20]; for (int i = 0; i < 20; ++i) { array_var[i] = i/2; array_var[i]++; System.out.print(array_var[i] + " "); i++; } } }

A. 1 2 3 4 5 6 7 8 9 10
B. 1 2 3 4 5
C. 0 1 2 3 4 5 6 7 8 9 10
D. 1 2 3 4 5 6 7 8 9
E. 0 1 2 3 4 5
Answer» B. 1 2 3 4 5
4.

What is the output of this program?public class output { public static void main(String args[]) { int p[] = {5,6,7,8,9}; int q[] = p; int sum = 0; for (int j = 0; j < 4; ++j) sum += (p[j] * q[j + 1]) + (p[j + 1] * q[j]); System.out.println(sum); } }

A. 400
B. 300
C. 200
D. 100
E. None of these
Answer» B. 300