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;
About Question enthuware.ocajp.i.v8.2.1414 :
Moderator: admin
-
- Posts: 20
- Joined: Sat Apr 23, 2016 2:52 pm
- Contact:
-
- Posts: 20
- Joined: Sat Apr 23, 2016 2:52 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1414 :
I guess the return type is Auto-boxed from primitive to reference type ?
-
- Site Admin
- Posts: 10068
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1414 :
Correct. parseBoolean returns a primitive but if you try to assign it to Boolean wrapper class variable, the returned value will be auto-boxed.JaredTse wrote:I guess the return type is Auto-boxed from primitive to reference type ?
If you like our products and services, please help us by posting your review here.
-
- Posts: 20
- Joined: Sat Apr 23, 2016 2:52 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.1414 :
Thank you.
Admin
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 148 guests