The ClassCastException occurs when Java attempts to cast an object of one type to another, incompatible type. One common occurrence…