The following diagram is given below along with the corresponding assignments:
In the above example
1) line 1 is given
2) line 2 represents Upcasting (You are assigning a subclass reference "x" to a parent class reference "a")
3) line 3 causes a ClassCastException because variable "x" is not a Human
4) Line 4 compiles and runs (reference variable x is referred to by an "Animal" reference variable "a")
5) Line 5 compiles and runs
6) line 6 causes a ClassCastException because Mammal is not a Human
7) line 7- Type mismatch: cannot convert from Animal to Mammal
Question: How does the double cast on line 5 work?
Mammal b = (Mammal) (Animal)x; // line 5 - Compiles and Runs
Lines 5 and 7 are almost the same except for line 5 contains (Mammal).
I am interested in knowing what enables line 5 to compile and run.