Page 1 of 1

About Question enthuware.ocpjp.i.v11.2.3219 : (LVTI)

Posted: Mon Oct 21, 2019 9:32 pm
by wdphipps
Hi EnthuWare team,

For "var" declaration, how is it that for a variable with value 1_______3 can be unambiguously inferred? What type would this be?

My confusion is that this value can be of several primitive types.

Any help would be greatly appreciated, as always!

Re: About Question enthuware.ocpjp.i.v11.2.3219 : (LVTI)

Posted: Mon Oct 21, 2019 10:52 pm
by admin
The value is a compile time constant and is indeed small enough to fit into a byte, char, short. It can also fit into a long, float, and double. So, it can be assigned to a variable of any of these types.

However, the value itself is an int literal and so the type of the var variable will be inferred as int.

Please see section 3.3.3 of OCP 11 Part 1 Fundamentals book. It explains the rules about literals:
A number without a decimal is considered an int literal, whereas a number containing a decimal point is considered a double literal.
HTH,
Paul.

Re: About Question enthuware.ocpjp.i.v11.2.3219 : (LVTI)

Posted: Tue Oct 22, 2019 6:50 pm
by wdphipps
This is clear, thank you!