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.

  1. A.

    The object will be automatically converted.

  2. B.

    Java will ignore the cast and continue.

  3. C.

    The compiler will throw a syntax error.

  4. D.

    The code will compile but throw ClassCastException at runtime.

Attempted by 209 students.

Show answer & explanation

Correct answer: D

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…