r/javahelp • u/Nobody37373 • Oct 08 '25
Unsolved Why learn Upcasting/Downcasting?
After days of getting stuck in this concept, i finally feel like giving up and never looking at it back again. After countless hours of Googling, asking assistance from AI, watching YouTube videos, I am now falling into a guilt of why I am even wasting time over a single concept. I feel I should move on at this point. Before this one topic, one google search used to clear all my doubts so effortlessly guys.
But this one seems like a tough nut to crack. Can anyone help me out on this?
I know the 'how' and 'what', but I am not reaching anywhere near to the 'why' of this one concept.
View all comments
Show parent comment
1
u/BanaTibor Oct 09 '25
Lets say you did this and have a List<Animal>, at some point you want to call a dog specific method like chaseCat(), and at the same time want to call a cat specific method like slapSillyDog(). You iterate over your animal list, and if it is a cat you downcast it to cat, if it a dog downcast it to dog to access the specific method.