100k views
4 votes
Which of the following promotions of primitive types is not allowed to occur? group of answer choices

a.char to int
b.double to float
c,int to double
d.short to long

User Hari
by
8.5k points

1 Answer

5 votes

Final answer:

The promotion that is not allowed without explicit casting is double to float, because double has a wider range than float and this conversion could result in loss of precision.

Step-by-step explanation:

The promotion in Java that is not allowed is b. double to float. Automatic type conversion (also known as type promotion) can occur when a value of one numeric type is assigned to another numeric type that is larger (or has a wider range). For instance, an int can be promoted to double, and a char can be promoted to int, since double and int have a wider range than int and char respectively. However, going from a double to float is not an automatic promotion, as double has a wider range than float and thus could result in a loss of precision. A casting operator is required to perform this conversion explicitly.

User Jonesy
by
7.8k points