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 Group https://bit.ly/infy_premium_group

We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.

Qtr No. 213, New Town Yehlanka Indore 454775

admin@prepflix.in