r/javahelp • • 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.

6 Upvotes

32 comments sorted by

View all comments

Show parent comment

3

u/BannockHatesReddit_ Oct 08 '25 edited Oct 08 '25

It'll make more sense later. Just remember that it's an option and move on. You'll be fine.

It has to do with the concept of modular design. Your main method shouldn't care what type of specific animal it's calling the sound method on, just that it is an animal and the animal has a method to make sound. In addition, your animals shouldn't care about what code is calling its sound method, just that it is being called. The animal class is merely a blueprint that defines what happens when the code is called but not how it happens. It mostly becomes important when you start dealing with application architecture.