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!
About Question enthuware.ocpjp.i.v11.2.3219 : (LVTI)
Moderator: admin
-
- Posts: 21
- Joined: Mon Sep 23, 2019 4:55 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3219 : (LVTI)
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:
Paul.
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:
HTH,A number without a decimal is considered an int literal, whereas a number containing a decimal point is considered a double literal.
Paul.
-
- Posts: 21
- Joined: Mon Sep 23, 2019 4:55 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3219 : (LVTI)
This is clear, thank you!
Who is online
Users browsing this forum: No registered users and 18 guests