Recall & Review
beginner
What is type casting in Java?
Type casting is converting a variable from one data type to another. It helps when you want to treat data as a different type.
Click to reveal answer
beginner
What is the difference between implicit and explicit type casting?
Implicit casting (widening) happens automatically when converting a smaller type to a bigger type (e.g., int to long). Explicit casting (narrowing) requires you to write the cast manually (e.g., double to int).
Click to reveal answer
beginner
How do you explicitly cast a double to an int in Java?
Use parentheses with the target type before the value: <br>
int x = (int) 9.7; <br> This cuts off the decimal part.Click to reveal answer
intermediate
What happens if you cast a large long value to an int?
If the long value is too big for int, the value wraps around and you get a different number. This is called overflow.
Click to reveal answer
intermediate
Can you cast between unrelated object types in Java?
No. You can only cast between compatible types in the same class hierarchy. Otherwise, you get a ClassCastException at runtime.Click to reveal answer
Which of these is an example of implicit type casting?
✗ Incorrect
Implicit casting happens when converting smaller types to bigger types automatically, like int to long.
What is the result of casting 9.99 (double) to int?
✗ Incorrect
Casting double to int cuts off the decimal part, so 9.99 becomes 9.
Which cast requires explicit syntax in Java?
✗ Incorrect
Casting from double to int is narrowing and requires explicit cast.
What exception occurs if you cast incompatible object types?
✗ Incorrect
Casting incompatible object types throws ClassCastException at runtime.
What happens if a large long value is cast to int?
✗ Incorrect
Casting large long to int truncates the value and may cause overflow.
Explain the difference between implicit and explicit type casting in Java.
Think about when Java does the conversion for you and when you must tell it to convert.
You got /6 concepts.
Describe what happens when you cast a double value to an int in Java.
Focus on how the number changes and what you must write in code.
You got /4 concepts.