Basically, upcasting is a casting of supertype whereas, downcasting is a casting of subtype. While doing downcasting it will involve a type check and can also throw an exception called ClassCastException.
For this case, upcast can be done because the dog is an animal. Also, you can do an upcast where there is an is-a relationship available between two classes. If you want to do the downcasting then this will look like this:
Animal animal = new Dog();
Dog castedDog = (Dog) animal;
I hope this will help.
Want to become a Java Expert? Join Java Course now!!