Page 1 of 1

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

Posted: Sat Apr 23, 2016 3:01 pm
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;

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

Posted: Sat Apr 23, 2016 3:03 pm
by JaredTse
I guess the return type is Auto-boxed from primitive to reference type ?

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

Posted: Sat Apr 23, 2016 8:58 pm
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.

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

Posted: Sun Apr 24, 2016 10:46 am
by JaredTse
:-)

Thank you.
Admin