Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.509 :

Posted: Tue Apr 24, 2012 10:15 am
by ETS User
Not sure what is meant by "...implicit narrowing is permitted only among byte, char, short, and int."

Assigning an int to a short requires a cast.

Re: About Question com.enthuware.ets.scjp.v6.2.509 :

Posted: Tue Apr 24, 2012 2:15 pm
by admin
Hi,
Implicit narrowing happens only for constants. A cast is not required for says byte b = 10; even though 10 is an int.

HTH,
Paul.

Re: About Question com.enthuware.ets.scjp.v6.2.509 :

Posted: Sat Jan 28, 2023 8:56 am
by asi-aal
Are we supposed to know that 43e1 produces a double and 0x0123 produces a float?

Re: About Question com.enthuware.ets.scjp.v6.2.509 :

Posted: Sat Jan 28, 2023 9:11 am
by admin
You do need to know the ways in which you can write a double value (such as 1.0 or 43e1 ) and the ways in which you can write an integral value (such as 1 or 0x0123 ). You also need to know that an integer value can be assigned to a float variable without a cast.

Re: About Question com.enthuware.ets.scjp.v6.2.509 :

Posted: Wed May 01, 2024 8:00 pm
by gadsgadsx
I missed because I wasn't sure about what 0x0123 means, and I thought that 43e1 fits into a double. Sadly I was wrong...