

MCQOPTIONS
Saved Bookmarks
This section includes 155 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.
51. |
What is the output of this program? class increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } |
A. | 25 |
B. | 24 |
C. | 32 |
D. | 33 |
Answer» D. 33 | |
52. |
What is the output of this program? class area { public static void main(String args[]) { double r, pi, a; r = 9.8; pi = 3.14; a = pi * r * r; System.out.println(a); } } |
A. | 301.5656 |
B. | 301 |
C. | 301.56 |
D. | 301.56560000 |
Answer» B. 301 | |
53. |
What is the output of this program? class evaluate { public static void main(String args[]) { int a[] = {1,2,3,4,5}; int d[] = a; int sum = 0; for (int j = 0; j < 3; ++j) sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]); System.out.println(sum); } } |
A. | 38 |
B. | 39 |
C. | 40 |
D. | 41 |
Answer» D. 41 | |
54. |
What is the output of this program? class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i/2; array_variable[i]++; System.out.print(array_variable[i] + " "); i++; } } } |
A. | 0 2 4 6 8 |
B. | 1 2 3 4 5 |
C. | 0 1 2 3 4 5 6 7 8 9 |
D. | 1 2 3 4 5 6 7 8 9 10 |
Answer» C. 0 1 2 3 4 5 6 7 8 9 | |
55. |
What is the output of this program? class variable_scope { public static void main(String args[]) { int x; x = 5; { int y = 6; System.out.print(x + " " + y); } System.out.println(x + " " + y); } } |
A. | 5 6 5 6 |
B. | 5 6 5 |
C. | Runtime error |
D. | Compilation error |
Answer» E. | |
56. |
Which of these is incorrect string literal? |
A. | “Hello World” |
B. | “Hello\nWorld” |
C. | “\”Hello World\”” |
D. | “\”HelloWorld\”” |
Answer» E. | |
57. |
What is the output of this program? class dynamic_initialization { public static void main(String args[]) { double a, b; a = 3.0; b = 4.0; double c = Math.sqrt(a * a + b * b); System.out.println(c); } } |
A. | 5.0 |
B. | 25.0 |
C. | 7.0 |
D. | Compilation Error |
Answer» B. 25.0 | |
58. |
What is the output of this program? class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'i'; System.out.print(array_variable[i] + "" ); i++; } } } |
A. | i i i i i |
B. | 0 1 2 3 4 |
C. | i j k l m |
D. | None of the mentioned |
Answer» B. 0 1 2 3 4 | |
59. |
What is the output of this program? class mainclass { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; if (var1) System.out.println(var1); else System.out.println(var2); } } |
A. | 0 |
B. | 1 |
C. | true |
D. | false |
Answer» D. false | |
60. |
What is the output of this program? class booloperators { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; System.out.println((var2 & var2)); } } |
A. | 0 |
B. | 1 |
C. | true |
D. | false |
Answer» E. | |
61. |
What is the output of this program? class asciicodes { public static void main(String args[]) { char var1 = 'A'; char var2 = 'a'; System.out.println((int)var1 + " " + (int)var2); } } |
A. | 162 |
B. | 65 97 |
C. | 67 95 |
D. | 66 98 |
Answer» C. 67 95 | |
62. |
What is the output of this program? class increment { public static void main(String args[]) { double var1 = 1 + 5; double var2 = var1 / 4; int var3 = 1 + 5; int var4 = var3 / 4; System.out.print(var2 + " " + var4); } } |
A. | 1 1 |
B. | 0 1 |
C. | 1.5 1 |
D. | 1.5 1.0 |
Answer» D. 1.5 1.0 | |
63. |
What is the output of this program? class Modulus { public static void main(String args[]) { double a = 25.64; int b = 25; a = a % 10; b = b % 10; System.out.println(a + " " + b); } } |
A. | 5.640000000000001 5 |
B. | 5.640000000000001 5.0 |
C. | 5 5 |
D. | 5 5.640000000000001 |
Answer» B. 5.640000000000001 5.0 | |
64. |
What is the output of this program? class increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } |
A. | 25 |
B. | 24 |
C. | 32 |
D. | 33 |
Answer» D. 33 | |
65. |
What is the output of this program? class Output { public static void main(String args[]) { int a = 1; int b = 2; int c; int d; c = ++b; d = a++; c++; b++; ++a; System.out.println(a + " " + b + " " + c); } } |
A. | 3 2 4 |
B. | 3 2 3 |
C. | 2 3 4 |
D. | 3 4 4 |
Answer» E. | |
66. |
What will be the output of the program? class Test { public static void main(String [] args) { int x=20; String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge"; System.out.println(sup); } } |
A. | small |
B. | tiny |
C. | huge |
D. | Compilation fails |
Answer» C. huge | |
67. |
Which three are legal array declarations? int [] myScores []; char [] myChars; int [6] myScores; Dog myDogs []; Dog myDogs [7]; |
A. | 1, 2, 4 |
B. | 2, 4, 5 |
C. | 2, 3, 4 |
D. | All are correct. |
Answer» B. 2, 4, 5 | |
68. |
In Java, the ……………………… is used to access the instance variables and methods of class objects. |
A. | dot operator(.) |
B. | instanceof |
C. | bitwise |
D. | conditional |
Answer» B. instanceof | |
69. |
When one of the operands is real and the other is integer, the expression is called a ……………………. expression. |
A. | hybrid |
B. | mix-mode-arithmetic |
C. | arithmetic |
D. | real-integer |
Answer» C. arithmetic | |
70. |
If a and b are integers, then for a=14 and b=4 what will be the value of expression a/b. |
A. | 3 |
B. | 2 |
C. | 4 |
D. | 1 |
Answer» B. 2 | |
71. |
What will be result of the result of the expression -14%-3 |
A. | 2 |
B. | -2 |
C. | 4 |
D. | -4 |
Answer» C. 4 | |
72. |
If a=20 and b=15 then the statement x=(a>b) ? a:b; will assign value of x. |
A. | 5 |
B. | 15 |
C. | 20 |
D. | 35 |
Answer» D. 35 | |
73. |
If int x=15; y=20; what will be the value of x after executing the following statement x=(x |
A. | 5 |
B. | 15 |
C. | 25 |
D. | 35 |
Answer» E. | |
74. |
When a=9, b=12 and c=3 what will be the value of x for the expression x=9-12/3+3*2-1 |
A. | 10 |
B. | 11 |
C. | 7 |
D. | 8 |
Answer» B. 11 | |
75. |
If j and k are int type variables, what will be the result of the expression j%k when j=10 and k=3? |
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
Answer» C. 2 | |
76. |
What will be the values of x, y and z after execution of the following statements?int x, y, z; x=9; y=10; z=++x=y++; |
A. | z=21, x=11, y=11 |
B. | z=20, x=10, y=11 |
C. | z=21, x=11, y=10 |
D. | z=20, x=10, y=10 |
Answer» C. z=21, x=11, y=10 | |
77. |
What will be the result of the expression of 8|8. |
A. | 16 |
B. | 1 |
C. | 8 |
D. | 64 |
Answer» D. 64 | |
78. |
To change the order in which expressions are evaluated …………………. are placed around the expression that are to be evaluated first. |
A. | ampersand |
B. | equals |
C. | parentheses |
D. | greater than |
Answer» D. greater than | |
79. |
When the operators are having the same priority, they are evaluated from ………………………….. in the order they appear in the expression. |
A. | left to right |
B. | right to left |
C. | any of the above |
D. | none of the above |
Answer» B. right to left | |
80. |
The ………………… statement tests the value of a given variable against a list of case values and when a match is found, a block of statements associated with that case is executed. |
A. | switch |
B. | break |
C. | continue |
D. | default |
Answer» B. break | |
81. |
When the operator ++ is placed after the variable name, first assignment of the value of the variable takes place and then the value of the variable is incremented, this operation is also called ………………………….. . |
A. | pre increment |
B. | post increment |
C. | left to right increment |
D. | right to left increment |
Answer» C. left to right increment | |
82. |
The ……………………… statement at the end of each block signals the end of a particular case and causes an exit from the switch statement, transferring the control to the statement following the switch. |
A. | switch |
B. | break |
C. | continue |
D. | default |
Answer» C. continue | |
83. |
The ………………. is an optional case, when it will be executed if the value of the expression does not match with any of the case values. |
A. | switch |
B. | break |
C. | continue |
D. | default |
Answer» E. | |
84. |
Here is a segment of a program x=1; y=1; if(n>0) x=x+1; y=y-1; what will be the values of x and y if n=1. |
A. | x=1, y=1 |
B. | x=0, y=2 |
C. | x=2, y=1 |
D. | x=2, y=0 |
Answer» E. | |
85. |
What will be the output of the following code. int j=50; while(true) { if(j<10) break; j=j-10; } System.out.println(“j is “+j); |
A. | Error |
B. | j is 0 |
C. | j is 50 |
D. | No output |
Answer» C. j is 50 | |
86. |
If you need to select among a large group of values, a switch statement will run much faster than the equivalent logic coded using ……………….. statement. |
A. | if |
B. | if-else |
C. | do-while |
D. | while |
Answer» C. do-while | |
87. |
The ………………………. loop is especially useful when you process a menu selection. |
A. | while |
B. | do-while |
C. | for |
D. | switch |
Answer» C. for | |
88. |
State output of the following code int x=20; int y=10; if(x>y) { if (y>10) System.out.println(“y is “+y); } else System.out.println(“x is “+x); |
A. | Error |
B. | x is 20 |
C. | y is 10 |
D. | No output |
Answer» E. | |
89. |
By using …………………….., you can force immediate termination of loop, bypassing the conditional expression and any remaining code in the body of the loop. |
A. | switch |
B. | break |
C. | continue |
D. | default |
Answer» C. continue | |
90. |
Which of the following control expressions are valid for an if statement? |
A. | an integer expression |
B. | a Boolean expression |
C. | either A or B |
D. | Neither A or B |
Answer» C. either A or B | |
91. |
In while and do-while loops, a ………………… statement causes control to be transferred directly to the conditional expression that controls the loop. |
A. | break |
B. | pause |
C. | start |
D. | continue |
Answer» E. | |
92. |
What will be the output of the following code. int x, y; x=15; y=20; if (x>15) if(y>15) { System.out.println(“y is “+y); } else System.out.println(“x is “+x); |
A. | Error |
B. | y is 20 |
C. | x is 15 |
D. | No output |
Answer» D. No output | |
93. |
The conditional statement, _______ can only test for equality, whereas _________ can evaluate any type of Boolean expression. |
A. | if, switch |
B. | switch, if |
C. | while, if |
D. | if, while |
Answer» C. while, if | |
94. |
What will be the output of the following code snippet? int a=15; int b=25; if ((a15) System.out.println(a); else System.out.println(b); |
A. | Error |
B. | 15 |
C. | 25 |
D. | No output |
Answer» C. 25 | |
95. |
__________ statement provides an easy way to dispatch execution to different parts of your code based on the value of an expression. |
A. | if-else |
B. | switch |
C. | if |
D. | while |
Answer» C. if | |
96. |
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); } } |
A. | 1 |
B. | 2 |
C. | 3 |
D. | 4 |
Answer» C. 3 | |
97. |
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); } } |
A. | 5 |
B. | 6 |
C. | 14 |
D. | compilation error |
Answer» C. 14 | |
98. |
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]; |
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
Answer» C. 2 | |
99. |
What is the output of this program? class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'i'; System.out.print(array_variable[i] + ""); } } } |
A. | 1 2 3 4 5 6 7 8 9 10 |
B. | 0 1 2 3 4 5 6 7 8 9 10 |
C. | i j k l m n o p q r |
D. | i i i i i i i i i i |
Answer» E. | |
100. |
What is the output of this program? class array_output { public static void main(String args[]) { int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}}; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3 ; ++j) sum = sum + array_variable[i][j]; System.out.print(sum / 5); } } |
A. | 8 |
B. | 9 |
C. | 10 |
D. | 11 |
Answer» C. 10 | |