Given:

void getValue(Object value) {
if (!(value instanceof Integer input))
 System.out.print("Integer!");
else if (!(value instanceof String input)) {  // Line 1
 throw new RuntimeException();
}
System.out.print("String!");
}

What is the output produced on calling getValue("integer")? (Assume the code is present inside in a valid class.)

Integer!

Integer! followed by an exception.

Pattern matching with an if statement is implemented using the instanceof operator.

Integer! String!

Verified Answer
Correct Option - f

To get all Infosys Certified Java SE 21 Developer Exam questions Join Telegram Group https://rebrand.ly/lex-telegram-236dee

Telegram