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

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

Moderator: admin

Post Reply
JaredTse
Posts: 20
Joined: Sat Apr 23, 2016 2:52 pm
Contact:

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

Post by JaredTse »

Hi All, this are quotes from the mock exam

"Boolean class has two static helper methods for creating booleans - parseBoolean and valueOf. Boolean.parseBoolean(String ) method returns a primitive boolean and not a Boolean object "


Boolean n = Boolean.parseBoolean("true");
System.out.println( n ); // => true
System.out.println( n.getClass() ); // => class java.lang.Boolean

boolean nn = Boolean.parseBoolean("true");
System.out.println( nn ); // => true

So how come in the answer says that it only returns primitive type.

or is because, when it says it returns a primitive type. it actually returns "true", and is the same thing as doing

Boolean n = true;

JaredTse
Posts: 20
Joined: Sat Apr 23, 2016 2:52 pm
Contact:

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

Post by JaredTse »

I guess the return type is Auto-boxed from primitive to reference type ?

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

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

Post by admin »

JaredTse wrote:I guess the return type is Auto-boxed from primitive to reference type ?
Correct. parseBoolean returns a primitive but if you try to assign it to Boolean wrapper class variable, the returned value will be auto-boxed.
If you like our products and services, please help us by posting your review here.

JaredTse
Posts: 20
Joined: Sat Apr 23, 2016 2:52 pm
Contact:

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

Post by JaredTse »

:-)

Thank you.
Admin

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 41 guests