The official document for ClassCastException says: =
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.
For Example: When you try to cast an Integer to a String ClassCastException will be thrown since String is not a subclass of Integer like below:
Object i = Integer.valueOf(42);
String s = (String)i; // ClassCastException thrown here.
Interested in Java? Check out this Java tutorial by Intellipaat.