Question: what is the difference between upcasting and downcasting in java?
Answer: Upcasting is casting to a supertype, while downcasting is casting to a subtype. Upcasting is always allowed, but downcasting involves a type check and can throw a ClassCastException . In your case, a cast from a Dog to an Animal is an upcast, because a Dog is-a Animal .