Learn Java Tutorial for Beginners, Part 29: Upcasting and Downcasting

///Learn Java Tutorial for Beginners, Part 29: Upcasting and Downcasting

Learn Java Tutorial for Beginners, Part 29: Upcasting and Downcasting

FavoriteLoadingAdd to favorites

Get complete courses at
This is a tutorial on upcasting and downcasting in Java, an important topic that you need to know to write Java programs effectively.

source

Java468x60
By |2019-05-04T18:40:57+00:00May 4th, 2019|Java Video Tutorials|20 Comments

20 Comments

  1. jvsnyc May 4, 2019 at 6:41 pm - Reply

    This makes me appreciate IS and AS from C# even more — is there still no direct equivalent in modern Java?

  2. jvsnyc May 4, 2019 at 6:41 pm - Reply

    Most people learning Java, or C# for that matter, will never do C++. So for them, it probably doesn't make too much difference whether you say variable or reference. But even there, in C#, as there is a big distinction between value types and reference types, I would prefer saying reference rather than variable. Here in the land of Java, it is probably fine to say variable rather than reference 99% of the time, but I think many people who are multi-lingual would gravitate to saying reference, since in both C# and C++ you can actually have variables (rather than references) of complex types, and it leaves no ambiguity. I do see a handful of confused people in the comments that perhaps would be less confused if we said reference everywhere. In C++ if you pass a subclass by value as a superclass, you actually get object slicing (OUCH!!), so it is of paramount importance to keep them clear. Many people watching these videos are going to be using only Java, so it is just a little thing I am pointing out, rather than some stark criticism or complaint.

  3. Zack Manesiotis May 4, 2019 at 6:41 pm - Reply

    Extremely helpful! Showed all cases, very easy to follow and well explained, keep it up

  4. adel al May 4, 2019 at 6:41 pm - Reply

    Many thanks for the perfect explanation. But, I wanna ask you, when this could be used?

  5. S V S SUKESH May 4, 2019 at 6:41 pm - Reply

    very clean and easy explanation …..healed me a lot

  6. Eighth_Wave May 4, 2019 at 6:41 pm - Reply

    Love the classical intro/outro btw. Sets the tone and makes things less intimidating 🙂

  7. Antony Helsby May 4, 2019 at 6:41 pm - Reply

    Nice video, I just wish he'd use a more natural voice instead of putting the constant smooth cloud on his voice. Sounds so narcissistic…that's just me anyway…

  8. magdalena zych May 4, 2019 at 6:41 pm - Reply

    when you get to the downcasting, it just gets confusing.

  9. Alina Aldea May 4, 2019 at 6:41 pm - Reply

    nice content

  10. Bhupinder singh May 4, 2019 at 6:41 pm - Reply

    i you give answer i will click on subscribe

  11. Bhupinder singh May 4, 2019 at 6:41 pm - Reply

    what is the need of uppcasting ?
    machine a=new machine();
    a.start();

    is similar to upcasting
    machine a=new Camera();
    a.start();

    i think both are same what is the need of upcasting

  12. Luke Sun May 4, 2019 at 6:41 pm - Reply

    very useful thank you!@

  13. shhiv ram May 4, 2019 at 6:41 pm - Reply

    At some point in all your tutorials, you start to sound like "The giving, the taking and the receiving" -Joey Tribbiani (FRIENDS 1994-2004)

  14. AY Huang May 4, 2019 at 6:41 pm - Reply

    This was very well explained. Thank you.

  15. Matt Jensen May 4, 2019 at 6:41 pm - Reply

    You are a savior and make java so much easier to understand. A lot of people are jibber jabber. Thank you!!! Passing a Final because of you!

  16. Keith Scull May 4, 2019 at 6:41 pm - Reply

    Would you guys tend to agree then, that it's correct to say in order to downcast your first will have to upcast, as following:

    //First the upcast needs to take place
    ParentClass parentObject = new ChildClass();

    //THEN, once the upcasting above is done we can downcast to render access of the //parentObject's implementations of the ChildClass's methods
    ChildClass childObject = (ChildClass) parentObject;

    //Notice we could NOT have done the directly-above downcasting had we NOT first had an object that was upcasted from type of parent to refer to object of child, I suppose downcast cannot exist without upcast?

  17. Aq May 4, 2019 at 6:41 pm - Reply

    The last part of the tutorial was quite confusing.
    Can you elaborate on references? What are they?

  18. MedG Absent May 4, 2019 at 6:41 pm - Reply

    thank u sir
    subscribed

  19. Rad Aplan May 4, 2019 at 6:41 pm - Reply

    excellent tutorial

  20. Guram Kankava May 4, 2019 at 6:41 pm - Reply

    Thank you very much.

Leave A Comment

*