Page 1 of 1

About printing of default values

Posted: Thu Dec 21, 2017 4:29 pm
by Rinkesh
Paul,I gave my exam today and got 75% which is good considering my first oracle certification exam.I had a question in exam which I wanna ask.I am asking here because I don't know where to ask and this is the place where you gave me your last reply.

There was a question which was printing char,boolean and float default values and there were 2 confusing options:-

a. char = 0 b. char =
boolean = false boolean = false
float = 0.0f float = 0.0

I marked a. because I remember you said that char is nothing but an unsigned integer and also because float doesn't have f with it in the second option.I have classes notes which says b. is the correct answer.So,Did I mark the right option or Wrong option?

Sorry for asking here but I am really passionate and you can delete it or I will delete it after my doubt is cleared.
Thank you in Advance.

Re: About printing of default values

Posted: Thu Dec 21, 2017 8:49 pm
by admin
Sorry, the correct answer should be b :(

Yes, char is an integral type but it is interpreted as a character. So while printing 0, the println method will using try to print the character associated with the number 0. This will print a blank.

An f is needed only while defining a float value to distinguish it from a double. But while printing, it will use Float.toString(f) to get a String representation of float, which is just 0.0.

Although question Q 2.1378 shows how a float is printed, we will add a question that cover this point more thoroughly.

thank you for your feedback!

Re: About printing of default values

Posted: Fri Dec 22, 2017 6:44 am
by Rinkesh
My Pleasure!