Page 1 of 1

About Question enthuware.ocpjp.v21.2.3669 :

Posted: Fri Oct 03, 2025 2:48 pm
by nnavlani
Integer r = i1+1000;
System.out.println(r); //This will print 3000
and
Integer r = i1 + Integer.valueOf(s1.replace("_", ""), 16); //This will throw an exception
System.out.println(r);
These two are right answers ?

Why is this being reported as one of the right answers ?
String s1 = "2_0";
Integer r = 100 + Integer(s1); //This will cause compilation failure
System.out.println(r);

Is there something wrong here?

Re: About Question enthuware.ocpjp.v21.2.3669 :

Posted: Sat Oct 04, 2025 9:39 am
by admin
There is nothing wrong. Wouldn't there be a compilation failure as the code say?
The problem statement is not asking you to pick the options that will compile or run. It just asking you to pick the right options. You have to check each option individually and see what it says. In this case, option 4 correctly identifies that this line will cause compilation failure and so it is a correct option.