Problem description
This exception occurs when you perform forced type conversion but the converted object is not the instance where type conversion occurs.
Solution
This exception occurs when you perform forced type conversion but the converted object is not the instance where type conversion occurs. You can execute the if(object instanceof)
statement to determine whether the type of an object can be forced to convert.
Sample code
public Son getSon(Father reference){
if(reference instanceof Son){
Son son=(Son)reference;
return son;
}
return null;
}