I believe, though I could be wrong , that a ClassCastException comes when you try to make a reference variable of a subclass type into a reference variable of a superclass type.

You can do this:...