Refer the below code snippet and predict the outcome.

public static void main(String args[]){
Integer intVar1 = null;
Integer intVar2 = new Integer(110);
Optional<Integer> optinalVar1 = Optional.ofNullable(intVar1);
Optional<Integer> optinalVar2 = Optional.of(intVar2);
System.out.println(optinalVar1.orElse(new Integer(0))+optinalVar2.get()); // Line9
}

Compilation fails at Line9 as orElse() method can't be used with an Optional variable

null

110

Runtime exception will be thrown at Line9 as get() method can't be used with an Optional variable

Correct Option - c

To get all Infosys Certified Java Programmer 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