Computer Programming (COPROG) Practice Test

Access More Questions
Which operation is an explicit narrowing cast?
Correct Answer:
int i = (int) 3.99;
Explanation:
Explicit narrowing cast means you force a value into a type with a smaller range or precision using a cast operator. In the first line, (int) 3.99 explicitly converts the floating-point literal to an int, which trims the fractional part and can lose information. That exact use of (int) is what makes it a narrowing cast. The other lines rely on implicit conversions during assignment. Moving from int to double, long, or float expands the representable range (a widening conversion) and doesn’t use an explicit cast, so they don’t demonstrate a narrowing cast.

Access more questions from this quiz

Continue to Computer Programming (COPROG) Practice Test for more practice questions and the full quiz experience.

Access More Questions