Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
Moderator: admin
-
Tester
- Posts: 34
- Joined: Mon Oct 30, 2023 11:55 am
-
Contact:
Post
by Tester »
Integer r = 100 + Integer(s1); //This will cause compilation failure
but explanation tells
1. the string "2_0" does not represent a valid int value and so, it will throw a NumberFormatException at runtime.
in first case "compilation failure" in the second "runtime". For me explanation looks right. Maybe its a good idea to correct the question?
-
admin
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
-
Contact:
Post
by admin »
The question and the answer both are correct. You missed the first two sentences of the explanation :
Integer(s1) is invalid because there is no such method in the given code.
new Integer(s1) would have been valid constructor invocation but -
.....
If you like our products and services, please help us by posting your
review here.
Users browsing this forum: No registered users and 218 guests