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?
About Question enthuware.ocpjp.v21.2.3669 :
Moderator: admin
-
- Posts: 8
- Joined: Sat Aug 02, 2025 11:21 pm
- Contact:
-
- Site Admin
- Posts: 10436
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v21.2.3669 :
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.
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.
Who is online
Users browsing this forum: No registered users and 117 guests