Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your 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 switchesI got this question by my school principal while I was bunking the class.This question is from Control Statements topic in section Operators and Control Statements of Java

Answer»

The CORRECT choice is (d) From INNERMOST loops or switches

For EXPLANATION I WOULD say: The break statement causes an EXIT from innermost loop or switch.

2.

Which of the following is not a decision making statement?(a) if(b) if-else(c) switch(d) do-whileThe question was posed to me in my homework.This interesting question is from Control Statements in portion Operators and Control Statements of Java

Answer»

Correct choice is (d) do-while

The best EXPLANATION: do-while is an ITERATION statement. OTHERS are DECISION making STATEMENTS.

3.

Which of the following is not a valid jump statement?(a) break(b) goto(c) continue(d) returnI had been asked this question during an online exam.My question is from Control Statements topic in chapter Operators and Control Statements of Java

Answer»

The CORRECT choice is (b) goto

For explanation I would say: break, continue and return transfer control to ANOTHER part of the program and returns back to caller after execution. However, goto is marked as not USED in JAVA.

4.

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 alwaysI have been asked this question in examination.Question is from Control Statements topic in section Operators and Control Statements of Java

Answer»

Right choice is (a) do statement executes the code of a loop at LEAST once

Easiest explanation: Do statement CHECKS the condition at the end of the loop. Hence, code GETS EXECUTED at least once.

5.

Which of the following is used with the switch statement?(a) Continue(b) Exit(c) break(d) doThis question was addressed to me in final exam.The above asked question is from Control Statements topic in section Operators and Control Statements of Java

Answer»

Right OPTION is (c) break

The BEST explanation: Break is used with a switch statement to SHIFT CONTROL out of switch.

6.

Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?(a) do-while(b) while(c) for(d) none of the mentionedI got this question in an online interview.My enquiry is from Control Statements in portion Operators and Control Statements of Java

Answer» RIGHT OPTION is (a) do-while

To ELABORATE: NONE.
7.

Which of these jump statements can skip processing the remainder of the code in its body for a particular iteration?(a) break(b) return(c) exit(d) continueI have been asked this question in unit test.My question is based upon Control Statements in section Operators and Control Statements of Java

Answer» CORRECT OPTION is (d) continue

To ELABORATE: NONE.
8.

The while loop repeats a set of code while the condition is not met?(a) True(b) FalseI had been asked this question by my school teacher while I was bunking the class.This interesting question is from Control Statements topic in section Operators and Control Statements of Java

Answer»

Right CHOICE is (B) False

Easy explanation: While loop repeats a set of code only until the CONDITION is MET.

9.

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 frameThis question was addressed to me in my homework.My question comes from Control Statements topic in section Operators and Control Statements of Java

Answer» CORRECT choice is (b) Break halts the EXECUTION and forces the control out of the loop

For EXPLANATION: Break halts the execution and forces the control out of the loop.
10.

Which of these are selection statements in Java?(a) if()(b) for()(c) continue(d) breakI had been asked this question in homework.This interesting question is from Control Statements topic in portion Operators and Control Statements of Java

Answer»

The CORRECT choice is (a) if()

Explanation: Continue and BREAK are jump statements, and for is a LOOPING STATEMENT.

11.

Which of these selection statements test only for equality?(a) if(b) switch(c) if & switch(d) none of the mentionedThis question was addressed to me during an interview for a job.Question is taken from Control Statements in chapter Operators and Control Statements of Java

Answer»

Correct OPTION is (b) SWITCH

The EXPLANATION: Switch statements checks for equality between the controlling VARIABLE and its constant cases.

12.

Which of these have highest precedence?(a) ()(b) ++(c) *(d) >>I had been asked this question during an internship interview.The origin of the question is Assignment Operators and Operator Precedence in chapter Operators and Control Statements of Java

Answer»

Right choice is (a) ()

The BEST I can EXPLAIN: ORDER of PRECEDENCE is (highest to lowest) a -> B -> c -> d.

13.

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 mentionedI had been asked this question in an international level competition.My doubt is from Relational Operators and Boolean Logic Operators topic in portion Operators and Control Statements of Java

Answer»

Correct answer is (c) BOOLEAN

The best I can explain: All relational OPERATORS RETURN a boolean value ie. true and false.

14.

What is the output of relational operators?(a) Integer(b) Boolean(c) Characters(d) DoubleThe question was posed to me by my school principal while I was bunking the class.This is a very interesting question from Relational Operators and Boolean Logic Operators topic in chapter Operators and Control Statements of Java

Answer»

The CORRECT CHOICE is (B) Boolean

The EXPLANATION: NONE.

15.

On applying Left shift operator,

Answer»

Right OPTION is (d) 31

Explanation: The LEFT SHIFT operator shifts all of the bits in a value to the left specified number of TIMES. For each shift left, the high order bit is shifted out and lost, zero is BROUGHT in from the right. When a left shift is applied to an integer operand, bits are lost once they are shifted past the bit position 31.

16.

Which operator is used to invert all the digits in a binary representation of a number?(a) ~(b) (d) ^I got this question in final exam.I'd like to ask this question from Bitwise Operators in division Operators and Control Statements of Java

Answer»

The CORRECT CHOICE is (a) ~

BEST explanation: Unary not OPERATOR, ~, inverts all of the BITS of its operand in binary representation.

17.

Which of these is not a bitwise operator?(a) &(b) &=(c) |=(d)

Answer»

Right option is (d) <=

Best explanation: <= is a RELATIONAL OPERATOR.

18.

Decrement operator, −−, decreases the value of variable by what number?(a) 1(b) 2(c) 3(d) 4This question was addressed to me during an online exam.I want to ask this question from Arithmetic Operators in division Operators and Control Statements of Java

Answer»

The CORRECT ANSWER is (a) 1

To ELABORATE: NONE.

19.

Modulus operator, %, can be applied to which of these?(a) Integers(b) Floating – point numbers(c) Both Integers and floating – point numbers(d) None of the mentionedI got this question by my school teacher while I was bunking the class.The origin of the question is Arithmetic Operators in section Operators and Control Statements of Java

Answer»

The correct option is (C) Both INTEGERS and FLOATING – point numbers

For EXPLANATION: Modulus OPERATOR can be applied to both integers and floating point numbers.

20.

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 mentionedThis question was addressed to me at a job interview.Origin of the question is Arithmetic Operators in section Operators and Control Statements of Java

Answer» RIGHT CHOICE is (d) NONE of the mentioned

The BEST I can EXPLAIN: None.
21.

Which of the following can be operands of arithmetic operators?(a) Numeric(b) Boolean(c) Characters(d) Both Numeric & CharactersThis question was posed to me in my homework.Asked question is from Arithmetic Operators topic in portion Operators and Control Statements of Java

Answer» CORRECT ANSWER is (d) Both Numeric & Characters

For EXPLANATION: The operand of arithmetic operators can be any of numeric or CHARACTER type, But not boolean.