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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

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

Post 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!

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

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

Post by wdphipps »

This is clear, thank you!

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests