ClassCastException is the child class of RunTimeException, hence it is an unchecked exception, This exception is automatically Raised by JVM Whenever we are trying to typecast the Parent class object to the child class object then we will get ClassCastException.
public class ClassCastException {
public static void main(String[] args) {
Object obj = new Object();
String str = (String) obj;
}
}
![](https://thecodedata.com/wp-content/uploads/2023/06/image-29-1024x59.png)
Similar Java Tutorials
- Odd Even in Java
- Method to print exception information in Java
- Exception Handling by Using try-catch in Java
- Checked Exception vs Unchecked Exception
- Exception Hierarchy in Java
- Java Exception Handling Interview Questions
- final finally finalize in java
- User Defined Exception in Java
- Exception Handling Keyword in Java
- throw throws in Java
- try with multiple catch block in Java