Upcasting/Downcasting in Java
问题 I am trying to understand upcasting and downcasting in Java and I am confused by the following scenario (about my code, which is below): First - why is it that the code does not compile when I include the line myAnimal.bark(); , and Second - (assuming I comment out myAnimal.bark(); ) why does calling myAnimal.move() print "moveDog" instead of "moveAnimal" ? Isn't myAnimal restricted to methods from the Animal class because we have declared its type to be Animal , even though we are setting it