Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Tommy Choe
38,156 PointsI don't understand the concept of upcasting or downcasting in Java.
I don't think I understand the concept of casting in general. I'm so used to Python where we don't have to declare/change types.
Can anyone explain it to me in detail? Thanks!
1 Answer
Luke Glazebrook
13,564 PointsHi Tommy!
Types are declared in Java so that the variable knows what it is supposed be holding. Like you say this isn't required in a language like Python but has to be stated in Java.
As part of Java as well you have to give the variable the same data type as what you stated it would hold. If you don't then your program will not run until you fix the issue.
I hope that I managed to clear this up for you a bit!
Tommy Choe
38,156 PointsTommy Choe
38,156 PointsThanks for the explanation Luke!