Explore topic-wise MCQs in Java Programming.

This section includes 30 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.

With x = 0, which of the following are legal lines of Java code for changing the value of x to 1? 1. x++; 2. x = x + 1; 3. x += 1; 4. x =+ 1;

A. 1, 2, 3 & 4
B. 3 & 2
C. 1 & 4
D. 1, 2 & 3
E. None of these
Answer» B. 3 & 2
2.

On applying Left shift operator, < 32 31 33 1 None of these

A. 32
B. 31
C. 33
D. 1
E. None of these
Answer» C. 33
3.

What is the output of this program?public class Output { public static void main(String args[]) { int p = 5; int q = 7; int r; int s; r = ++q; s = p++; r++; q++; ++p; System.out.println(p + " " + q + " " + r); } }

A. 6 7 7
B. 5 8 8
C. 7 9 9
D. 7 6 6
E. 8 7 7
Answer» D. 7 6 6
4.

What is the output of this program?public class RightShift_Operator { public static void main(String args[]) { int a; a = 100; a = a &gt;&gt; 1; System.out.println(a); } }

A. 10
B. 20
C. 30
D. 40
E. 50
Answer» F.
5.

What is the output of this program?public class LeftShift_Operator { public static void main(String args[]) { byte A = 65; int i; byte b; i = A &lt;&lt; 2; b = (byte) (A &lt;&lt; 2); System.out.print(i + " " + b); } }

A. 250 2
B. 260 2
C. 260 4
D. 230 6
E. 210 4
Answer» D. 230 6
6.

Which of the following operators can operate on a boolean variable? 1. &amp;&amp; 2. == 3. ?: 4. +=

A. 1 & 4
B. 1, 2 & 3
C. 1, 2 & 4
D. 3 & 2
E. None of these
Answer» C. 1, 2 & 4
7.

What is the output of this program?public class Output { public static void main(String args[]) { int p = 5; int q = 6; int r = 7; p |= 4; q &gt;&gt;= 1; r &lt;&lt;= 1; p ^= r; System.out.println(p + " " + q + " " + r); } }

A. 11 3 14
B. 10 10 10
C. 11 2 15
D. 11 2 14
E. 2 3 14
Answer» B. 10 10 10
8.

What is the output of this program?public class ternary_operator_Example { public static void main(String args[]) { int a = 5; int b = ~ a; int c; c = a &gt; b ? a : b; System.out.print(c); } }

A. 6
B. 4
C. 3
D. 5
E. 2
Answer» E. 2
9.

What is the output of this program?public class bool_operator_Example { public static void main(String args[]) { boolean p = true; boolean q = !true; boolean r = p | q; boolean s = p &amp; q; boolean z = s ? q : r; System.out.println(s + " " + z); } }

A. false true
B. true false
C. true ture
D. false false
E. None of these
Answer» B. true false
10.

What is the output of this program?public class Relational_operator_Example { public static void main(String args[]) { int num1 = 7; int num2 = 6; System.out.print(num1 &gt; num2); } }

A. true
B. false
C. 1
D. 0
E. None of these
Answer» B. false
11.

What is the value stored in p in following lines of code? int p, q, r; p = 0; q = 1; p = q = r = 8;

A. 9
B. 8
C. 7
D. 6
E. 5
Answer» C. 7
12.

What is the output of this program?public class operators_Example { public static void main(String args[]) { int num1 = 10; int num2 = 20; int num3; num3 = num2 + num2 * num1 / num2 + num2; System.out.print(num3); } }

A. 50
B. 40
C. 30
D. 20
E. 10
Answer» B. 40
13.

What is the output of this program?public class Bitwise_Operator { public static void main(String args[]) { int num1 = 30; int num2 = ~num1; System.out.print(num1 + " " + num2); } }

A. 30 -31
B. 40 -40
C. 30 -30
D. 31 -30
E. -40 41
Answer» B. 40 -40
14.

What is the order of precedence (highest to lowest) of following operators? 1. &amp; 2. ^ 3. ?:

A. 3 -> 2 -> 1
B. 1 -> 2 -> 3
C. 2 -> 1 -> 3
D. 2 -> 3 -> 1
E. None of these
Answer» C. 2 -> 1 -> 3
15.

What is the output of this program?public class Bitwise_Operator { public static void main(String args[]) { int p = 8; int q = 8; int r = p | q; int s = p &amp; q; System.out.println(r + " " + s); } }

A. 9 9
B. 7 7
C. 8 8
D. 10 10
E. 5 5
Answer» D. 10 10
16.

What should be expression1 evaluate to in using ternary operator as in this line? expression1 ? expression2 : expression3

A. Boolean
B. Floating point numbers
C. Integer
D. float
E. None of these
Answer» D. float
17.

What is the output of this program?public class Modulus_Example { public static void main(String args[]) { double p = 10.34; int q = 20; p = p % 15; q = q % 20; System.out.println(p + " " + q); } }

A. 10 0.0
B. 11 10.00
C. 10.22 10
D. 10.34 0
E. 2 10.21
Answer» E. 2 10.21
18.

What is the output of this program?public class increment _Example { public static void main(String args[]) { int a = 5; System.out.print(++a * 10); } }

A. 50
B. 60
C. 70
D. 80
E. 90
Answer» C. 70
19.

What is the output of this program?public class Increment { public static void main(String args[]) { double num1 = 5 + 10; double num2 = num1 / 6; int num3 = 10 + 5; int num4 = num3 / 6; System.out.print(num2 + " " + num4); } }

A. 0 2
B. 2.5 2
C. 2.5 1
D. 3 2
E. 1 1
Answer» C. 2.5 1
20.

Which of these lines of code will give better performance? 1. p | 8 + r &gt;&gt; q &amp; 10; 2. (p | ((( 8 * r) &gt;&gt; q ) &amp; 10 ))

A. 2 will give better performance as it has parentheses.
B. Dependent on the computer system.
C. 1 will give better performance as it has no parentheses.
D. Both 1 & 2 will give equal performance.
E. None of these
Answer» E. None of these
21.

What is the output of this program?public class Result{ public static void main(String args[]) { int q,r; int p=q=r=26; System.out.print(+p); } }

A. 25
B. 26
C. 27
D. 24
E. 23
Answer» C. 27
22.

What is the output of this program?public class operators { public static void main(String args[]) { int p = 10; System.out.println(++p * 5 + " " + p); } }

A. 44 11
B. 33 11
C. 55 11
D. 66 11
E. 11 55
Answer» D. 66 11
23.

What is the output of this program?public class Result { public static void main(String args[]) { int p , q = 1; p = 20; if(p != 20 &amp;&amp; p / 0 == 0) System.out.println(q); else System.out.println(++q); } }

A. 0
B. 1
C. 2
D. 3
E. 4
Answer» D. 3
24.

What is the output of this program?public class Result { public static void main(String args[]) { int p,q,r,s; p=q=r=s=10; p+=q-=r*=s/=10; System.out.println(p+" "+q+" "+r+" "+s); } }

A. 20 0 20 1
B. 10 0 10 1
C. 10 0 0 10
D. 20 0 0 20
E. 10 10 0 1
Answer» C. 10 0 0 10
25.

What is the value stored in p in following lines of code?

A. 9
B. 8
C. 7
D. 6
E. 5
Answer» C. 7
26.

Which of the following operators can operate on a boolean variable?

A. 1 & 4
B. 1, 2 & 3
C. 1, 2 & 4
D. 3 & 2
E. None of these
Answer» C. 1, 2 & 4
27.

On applying Left shift operator,

A. 32
B. 31
C. 33
D. 1
E. None of these
Answer» C. 33
28.

Which operator is used to invert all the digits in binary representation of a number?

A. <<<
B. ^
C. >>>
D. ~
E. None of these
Answer» E. None of these
29.

Which of these is returned by greater than , less than and equal to operators?

A. Boolean
B. Floating point numbers
C. Integers
D. None of these
E. NA
Answer» B. Floating point numbers
30.

Decrement operator, , decreases value of variable by what number?

A. 4
B. 1
C. 2
D. 3
E. None of these
Answer» C. 2