Mastering Java: The Ultimate Quiz for 'Thinking in Java' 2026 - Free Java Programming Practice Questions and Study Guide

Session length

1 / 730

What exception is thrown if a downcast fails in Java?

NullPointerException

ClassCastException

A downcast in Java is when an object is converted from a superclass type to a subclass type. The ClassCastException is thrown when an attempt to perform this conversion fails, indicating that the object is not an instance of the specified subclass. This is different from a NullPointerException, which is thrown when a null object is accessed, and from a RuntimeException, which is a general exception that is not specifically related to downcasting. Similarly, an IllegalArgumentException is thrown when an invalid argument is passed to a method, so it is not directly related to downcasting. Thus, the ClassCastException is the most appropriate exception to be thrown when a downcast fails in Java.

Get further explanation with Examzify DeepDiveBeta

RuntimeException

IllegalArgumentException

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy