Explore topic-wise MCQs in Java.

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

1.

From where break statement causes an exit?

A. Only from innermost loop
B. Terminates a program
C. Only from innermost switch
D. From innermost loops or switches
Answer» E.
2.

What is true about do statement?

A. do statement executes the code of a loop at least once
B. do statement does not get execute if condition is not matched in the first iteration
C. do statement checks the condition at the beginning of the loop
D. do statement executes the code more than once always
Answer» B. do statement does not get execute if condition is not matched in the first iteration
3.

The while loop repeats a set of code while the condition is not met?

A. True
B. False
Answer» C.
4.

What would be the output of the following code snippet if variable a=10?

A. 1 2
B. 2 3
C. 1 3
D. 3View Answer
Answer» E.
5.

Which of the following for loop declaration is not valid?

A. for ( int i = 99; i >= 0; i / 9 )
B. for ( int i = 7; i <= 77; i += 7 )
C. for ( int i = 20; i >= 2; - -i )
D. for ( int i = 2; i <= 20; i = 2* i )
Answer» B. for ( int i = 7; i <= 77; i += 7 )
6.

Which two are acceptable types for x?

A. short
B. char
C. long
D. float
Answer» B. char
7.

What is the valid data type for variable "a" to print "Hello World"?

A. int and float
B. byte and short
C. char and long
D. byte and char
Answer» E.
8.

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

A. 0
B. 1
C. 9
D. 8
Answer» E.
9.

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

A. Integer
B. Floating - point numbers
C. Boolean
D. None of the mentioned
Answer» D. None of the mentioned
10.

Evaluate the value of the expression?

A. 14
B. 12
C. 13
D. 10
Answer» D. 10
11.

What is/are highest order precedence operator(s) in Java?

A. ( )
B. { }
C. both a and b
D. None of these
Answer» D. None of these
12.

What is the order of precedence (highest to lowest) of following operators?

A. 1 -> 2 -> 3
B. 2 -> 1 -> 3
C. 3 -> 2 -> 1
D. 2 -> 3 -> 1
Answer» B. 2 -> 1 -> 3
13.

With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?

A. 1, 2 & 3
B. 1 & 4
C. 1, 2, 3 & 4
D. 3 & 2
Answer» D. 3 & 2
14.

Decrement operator '--' decreases the value of variable by what number?

A. 1
B. 2
C. 3
D. 4
Answer» B. 2
15.

Which of the following is an iteration statement?

A. switch
B. if-else
C. if
D. do-while
Answer» E.
16.

The && and || operators

A. Compare two boolean values
B. Compare two numeric values
C. Combine two boolean values
D. Combine two numeric values
Answer» D. Combine two numeric values
17.

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

A. Integers
B. Floating - point numbers
C. Boolean
D. None of the mentioned
Answer» D. None of the mentioned
18.

Which two of the following statements, inserted independently, could legally be inserted into missing section of this code?1. boolean test = (Component instanceof t);2. boolean test = (t instanceof Ticker);3. boolean test = t.instanceof(Ticker);4. boolean test = (t instanceof Component);

A. 1 and 4
B. 2 and 3
C. 1 and 3
D. 2 and 4
Answer» E.
19.

_______ is not a flow control statement in Java.

A. break
B. continue
C. exit()
D. return
Answer» D. return
20.

The break statement causes an exit from ______ loop.

A. innermost
B. outermost
C. break statement causes an exit from program
D. Depends on program
Answer» B. outermost
21.

Which three statements are true?1. f1 == f22. f1 == f33. f2 == f1[1]4. x == f1[0]f5. == f1[0]

A. 1, 2 and 3
B. 2, 4 and 5
C. 3, 4 and 5
D. 1, 4 and 5
Answer» C. 3, 4 and 5
22.

Which two statements are equivalent?1. 16*42. 16>>23. 16/2^24. 16>>>2

A. 1 and 2
B. 2 and 4
C. 3 and 4
D. 1 and 3
Answer» C. 3 and 4
23.

Which two statements are equivalent?1. 3/22. 3<23. 3*44. 3<<2

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

Which two are acceptable types for x?1. byte2. long3. char4. float5. Short6. Long

A. 1 and 3
B. 2 and 4
C. 3 and 5
D. 4 and 6
Answer» B. 2 and 4
25.

Determine the output of following code.

A. If a is true and b is true then the output is "A && B"
B. If a is true and b is false then the output is "notB"
C. If a is false and b is true then the output is "ELSE"
D. If a is false and b is false then the output is "ELSE"
Answer» D. If a is false and b is false then the output is "ELSE"
26.

Which of the following are legal lines of code?1. int w = (int)888.8;2. byte x = (byte)1000L;3. long y = (byte)100;4. byte z = (byte)100L;

A. 1 and 2
B. 2 and 3
C. 3 and 4
D. All statements are correct.
Answer» E.
27.

Which two are equal?1. 32/42. (8 >> 2) << 43. 2^54. 128 >>> 25. 2 >> 5

A. 1 and 2
B. 2 and 4
C. 1 and 3
D. 2 and 3
Answer» C. 1 and 3
28.

Which of these lines of code will give better performance?

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

What is the valid data type for variable “a” to print “Hello World”?

A. int and float
B. byte and short
C. char and long
D. byte and char
Answer» E.
30.

Which of these statements is correct?

A. true and false are numeric values 1 and 0
B. true and false are numeric values 0 and 1
C. true is any non zero value and false is 0
D. true and false are non numeric values
Answer» E.
31.

Which of these statements are incorrect?

A. The left shift operator, <<, shifts all of the bits in a value to the left specified number of times
B. The right shift operator, >>, shifts all of the bits in a value to the right specified number of times
C. The left shift operator can be used as an alternative to multiplying by 2
D. The right shift operator automatically fills the higher order bits with 0
Answer» E.
32.

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

A. 3 & 2
B. 1 & 4
C. 1, 2 & 4
D. 1, 2 & 3
Answer» E.
33.

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

A. Integers
B. Floating – point numbers
C. Boolean
D. None of the mentioned
Answer» D. None of the mentioned
34.

What would be the output of the following codesnippet if variable a=10?

A. 1 2
B. 2 3
C. 1 3
D. 3
Answer» E.
35.

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

A. Integer
B. Floating – point numbers
C. Boolean
D. None of the mentioned
Answer» D. None of the mentioned
36.

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

A. 1 -> 2 -> 3
B. 2 -> 1 -> 3
C. 3 -> 2 -> 1
D. 2 -> 3 -> 1
Answer» B. 2 -> 1 -> 3
37.

What is the value stored in x in following lines of code? int x, y, z; x = 0; y = 1; x = y = z = 8;

A. 0
B. 1
C. 9
D. 8
Answer» E.
38.

In the following code snippet, which lines of code contain error?

A. Line 2
B. Line 3
C. Line 4
D. Line 5
Answer» B. Line 3
39.

Which of these statements are incorrect?

A. Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms
B. Assignment operators run faster than their equivalent long forms
C. Assignment operators can be used only with numeric and character data type
D. None of the mentioned
Answer» E.
40.

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
B. 1 & 4
C. 1, 2, 3 & 4
D. 3 & 2
Answer» D. 3 & 2
41.

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

A. 1
B. 2
C. 3
D. 4
Answer» B. 2
42.

Which of the following will produce a value of 10 if x = 9.7?

A. round(x)
B. floor(x)
C. rint(x)
D. abs(x)
Answer» E.
43.

Which Control Statements allow the program to choose different paths of execution?

A. Selection
B. Collection
C. None of above
D. Iteration
Answer» B. Collection
44.

Which of the following will produce a value of 22 if x=22.9:

A. Round(x)
B. Ceil(x)
C. Abs(x)
D. Rint(x)
Answer» E.
45.

Which Control Statements enable program execution to repeat one or more statements?

A. Collection
B. Selection
C. None of above
D. Iteration
Answer» C. None of above
46.

WHICH_OF_THE_FOLLOWING_IS_NOT_A_VALID_JUMP_STATEMENT??$

A. break
B. goto
C. continue
D. return
Answer» B. goto
47.

int and float

A. byte and short
B. char and long
C. byte and char
Answer» C. byte and char
48.

Which of the following is used with the switch statement?

A. Continue
B. Exit
C. break
D. do
Answer» E.
49.

Which of this statement is incorrect?

A. switch statement is more efficient than a set of nested ifs
B. two case constants in the same switch can have identical values
C. switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression
D. it is possible to create a nested switch statements
Answer» C. switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression
50.

What is true about a break?

A. Break stops the execution of entire program
B. Break halts the execution and forces the control out of the loop
C. Break forces the control out of the loop and starts the execution of next iteration
D. Break halts the execution of the loop for certain time frame
Answer» B. Break halts the execution and forces the control out of the loop