About Question enthuware.ocajp.i.v8.2.1416 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Mikhail Volkov
Posts: 8
Joined: Mon Jul 29, 2019 11:25 am
Contact:

About Question enthuware.ocajp.i.v8.2.1416 :

Post by Mikhail Volkov »

Hello! Please explain to me.
Answer B: Boolean.parseBoolean("true")
Although this will return true but it is still not a valid answer because parseBoolean returns a primitive(!!!!!) and not a Boolean wrapper object.
But why code below doesn't call any error?

Boolean b1 = Boolean.parseBoolean("true"); // There is Boolean. It is wrapper!? Why it is working?
boolean b2 = Boolean.parseBoolean(" _true_ ");
System.out.println(b1); //true
System.out.println(b2); // false

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1416 :

Post by admin »

Because the question explicitly asks you to pick options that yield a Boolean wrapper object.
The question is not about valid assignment. Boxing/unboxing happens in an assignment and so a wrapper may be assigned to a primitive variable and vice-versa but that is not what this question is asking about.
If you like our products and services, please help us by posting your review here.

Mikhail Volkov
Posts: 8
Joined: Mon Jul 29, 2019 11:25 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1416 :

Post by Mikhail Volkov »

***Boxing/unboxing happens in an assignment*** - it was not clear for me.
I understood. Thanks you!!!

Post Reply

Who is online

Users browsing this forum: No registered users and 73 guests