Search code examples
javapolymorphismdowncast

Automatic downcast during method calls in Java


So I have been reading this great article about polymorphysm in Java Upcasting and Downcasting in Java and I encounter "automatic downcast during method calls" which the author did not explain in the article but he mentioned its very useful when we want to use polymorphysm.

Anybody can help me understand what it means ?


Solution

  • The statement "Polymorphism uses automatic downcast during method calls" is a very unfortunate attempt on behalf of the author to convey the fact that you can invoke "animal.speak();" and the animal will receive the call and process it as a "cat" or "dog" or whatever it is that the animal really is.

    So, the author perversely thinks of this as automatic downcasting during a method call: you invoke an animal, and what ends up being invoked is a cat.

    You can tell by the drawings that this is not a very high quality tutorial.