What will happen if an invalid downcast is attempted in Java at runtime?
2025
What will happen if an invalid downcast is attempted in Java at runtime?
Answer: D. The code will compile but throw ClassCastException at runtime.
- A.
The object will be automatically converted.
- B.
Java will ignore the cast and continue.
- C.
The compiler will throw a syntax error.
- D.
The code will compile but throw ClassCastException at runtime.
Attempted by 209 students.
Show answer & explanation
Correct answer: D
Loading lesson…