Upcasting and Downcasting in Java - Full Tutorial

Поделиться
HTML-код
  • Опубликовано: 30 янв 2025

Комментарии • 350

  • @arturmelo3681
    @arturmelo3681 Год назад +29

    the "meow" at 5:05 was the best part of the video, thanks john

  • @callmesej6935
    @callmesej6935 3 года назад +168

    I have my java exam in university in 15 days and I was so stressed about it but watching your videos made it so easy to understand Java. Lots of love to you from Stockholm. :)

    • @samcousins3204
      @samcousins3204 3 года назад

      hvordan var det?

    • @jospherstudies
      @jospherstudies 2 года назад +9

      really? i got my sem exam tommorow and its 9pm now. i just started now btw. people get sick very quickly bruh

    • @callmesej6935
      @callmesej6935 2 года назад

      @@jospherstudies omg good luck.

    • @callmesej6935
      @callmesej6935 2 года назад

      @@samcousins3204 det var inte så dåligt haha

    • @Ali-kg6mv
      @Ali-kg6mv 2 года назад +4

      I have mine tomorrow, and I'm learning more here than I have in class.

  • @Christian-ry3ol
    @Christian-ry3ol 2 года назад +31

    I've been learning java for a few years and NEVER had such a good explanation about this. Thank you John you're saving my degree.

  • @robert4598
    @robert4598 3 года назад +4

    What the f... those are the best explanations I've heard so far. That sums up 3 hours of Uni lecture in 10 minutes!

  • @renzotorr537
    @renzotorr537 3 года назад +68

    Great video, loving your channel so far! I want to add for new learners: One of the most important uses of upcasting is when you have an ArrayList, List, LinkedList, etc, and you can make it of type Animal while adding all types of animals like Cats, Dogs and whatever

    • @rolay8043
      @rolay8043 3 года назад +1

      yeah and after that you can check for each animal (if you wish) what kind of animals they actually are, to use specific methods

    • @moltony
      @moltony 2 года назад

      TX tjh

    • @smrtfasizmu6161
      @smrtfasizmu6161 2 года назад +6

      Or you can have an array as well. Array of chess pieces for instance. And then every chess piece is actually a pawn, knight, bishop, rook, queen or a king but they are all upcasted as chess pieces in the array.

    • @rickmemmer5625
      @rickmemmer5625 2 года назад +1

      Thank you for sharing that. Appreciate it!

  •  2 года назад +4

    Lots of people know Java very well, but only a handful of people know how to pass the knowledge on. Congrats for being one of them!!!

  • @yssvxfrY
    @yssvxfrY 15 дней назад

    I'm watching this video literally less than 2 hours before my test and it has helped me a lot, thank You very much. (I'll make sure to study more for the next time )

  • @findlestick
    @findlestick 3 года назад +46

    Excellent, clear video. Thanks. 😊
    Also, I liked the characterisation you gave Java… it trusted us “but we betrayed its trust by throwing-in a cat” 😂

    • @mo0ndawg
      @mo0ndawg 2 года назад +2

      This made me genuinely laugh 😂.
      And at the end of it all, we come to know that good code is does not trust people. Better safe than sorry 🙌🏼

  • @KAROMII1
    @KAROMII1 2 года назад +5

    for a week i was trying to wrap my head around why we would need to cast objects, this literally lifted a weight off my shoulders thank you!

    • @rickmemmer5625
      @rickmemmer5625 2 года назад

      I know the feeling -- and this video just blew that door wide open. What a relief!! :o)

  • @MishaKoroliov
    @MishaKoroliov 2 года назад +2

    I've been searching for a specific answer for over and hour, came over your video and got the answer in less than 5 minute, thank you very much!

  • @beat-fustudio8910
    @beat-fustudio8910 2 года назад +1

    I try to teach my daughter about upcasting and downcasting for 2 weeks with no avail, And she immediately got it after watching this video, Best explanation !

  • @SoftwareTestSolutions
    @SoftwareTestSolutions 3 года назад +5

    Loved this again! My 9 years old son is watching you on RUclips and practicing the Java.

    • @lookupverazhou8599
      @lookupverazhou8599 3 года назад

      @Daniel Bunting Having a stable career in 9 years, as well as making hardware do exactly what you want it to do is indeed a fun life.

  • @RowaidAsaba
    @RowaidAsaba Год назад

    The best enjoyable way to learn Java is your lovely channel. I appreciate your efforts.

  • @josephthecreator
    @josephthecreator 3 года назад +3

    HANDS DOWN the absolute best channel I've found regarding Java tutorials and explanations. Thank you John!

  • @Domo22xD
    @Domo22xD 2 года назад +7

    I love it 8:10 "and than we betray that trust, and we send in a cat" 😂😂😂😂😂

  • @asaphferreira6448
    @asaphferreira6448 11 месяцев назад +1

    Sir, your explanation is amazing. Thank you a lot.

  • @IhasDag
    @IhasDag 5 месяцев назад

    I'm actually amazed how easy you made this concept for me. Also I like how you explain why such concepts are necessary. Thanks you for your videos.

  • @dominiqueradtke1262
    @dominiqueradtke1262 11 месяцев назад

    This was so helpful! My professor just randomly assumed that we know what casting is and I didn't quite get the hang of it til this video! Thanks!!

  • @BGP_23
    @BGP_23 Год назад +1

    Love your videos John, I am using them to supplement the course materials in my intermediate java college course. They are extremely helpful for a 52 year old.

  • @smrtfasizmu6161
    @smrtfasizmu6161 2 года назад +9

    I remember watching this video a couple of months ago. That was the moment I understood downcasting and upcasting. The book that I was reading explained it so poorly that I wasn't able to understand what was going on, how downcasting and upcasting work. This guy is such a talented teacher, in 10 minutes he perfectly explained a topic which I wasn't able to understand whatsoever.

  • @emreibrahim8504
    @emreibrahim8504 Год назад

    this video is life saver, nobody on internet explained it this way, whenever i read an article or watch a video about up/down casting they just tell you the syntax which is pretty easy, but i never understood the concept of it, why should i use up/down casting? since i already can call each method from it's own object? but finally i found this video although i'm coming from C# background and i could still understand everything he said. Thumbs up for this man!

  • @MyDisal
    @MyDisal 3 года назад +10

    High quality stuff, I'm learning C# but the underlying concepts are very well taught, even if it's in Java. Thank you!

    • @c.ladimore1237
      @c.ladimore1237 2 года назад +1

      i like c# over java (very different usages), but (don't kill me) javascript over c# for game dev. in unity, even though they dropped it. slower, but easier to write IMO

    • @itzdm0r3
      @itzdm0r3 Год назад

      They're both OOP languages so a lot of the underlying concepts are the same as other "C" based ones.

  • @evangrove599
    @evangrove599 2 года назад

    I was taking this online java course and in it they threw in upcasting and down casting while teaching polymorphism without explaining what this casting is. This was such a great explanation!

  • @chiranjibdash1843
    @chiranjibdash1843 3 года назад +1

    Thank you so much for explaining these concepts. I'm learning java. I'm new to to your channnel. No one can explain concepts in more simple way other than you. Keep uploading new tutorials.

  • @lynnwai152
    @lynnwai152 10 месяцев назад

    The best explanation of casting ever. Thanks, John.

  • @sabari360
    @sabari360 3 года назад

    OMG ! this video made my day , I have been searching for upcast and downcast for a day , none cleared me , but the example in your video told why we have to use this upcast and downcast , caught my mind , thankyou so much , you are an amazing explainer. and I subscribed your channel , keep posting amazing contents.

  • @halilibrahimustun50
    @halilibrahimustun50 2 года назад +1

    You are awesome! I've been searching the answer of this type of code on the internet for a couple of days and even in the stack overflow I couldn't find a satisfactory answer. You made it crystal clear. One more time, Thank you :)

  • @manarsalem1685
    @manarsalem1685 8 месяцев назад

    I still had my doubts about this despite having read my textbook and having attended my university lecture about this two times. I don't normally comment but THANKS A TON for explaining this in just 10 minutes! May God bless you 💞

  • @sydneygoeury6102
    @sydneygoeury6102 3 года назад +5

    Man that's quality content here! Thanks for this, I'm a CS major and it helps me a lot in my Java class.

    • @smrtfasizmu6161
      @smrtfasizmu6161 2 года назад +2

      Yes, he made the concept easy to understand while the book that I was reading made this concept unnecessary hard. Someone posted a sequence from their book which "explains" casting in Java and yeah, you can see how bad the "explanation" is. It is more of a description of casting for people who already understand what casting is and who are experienced in Java then it is an explanation aimed at learners who don't already understand casting and who are Java beginners. People who write such books are talented, it is not easy to make such easy concepts hard to understand, but they manage to do it.

  • @smrtfasizmu6161
    @smrtfasizmu6161 3 года назад +1

    What a great video! I am reading a book on Java and I didn't understand downcasting, upcasting, instanceof at all until I watched this video. This explanation is so much better than the explanation in my book.

  • @mahzadseyedalikhani9865
    @mahzadseyedalikhani9865 2 года назад

    This vidio survived me from miss understanding. After reading lots of blogs and watch some videos, just your vidio clarified all the concepts and reasons to me🤩

  • @Cablur
    @Cablur Год назад

    Mate, what a great and fully comprehensive video about this subject on which I smacked my head at the wall the whole day ❤

  • @LuckyMakhado
    @LuckyMakhado 3 года назад

    First time RUclips recommendation worked for me. Came across you video's and haven't stopped watching ever since. Thank you so much, your explanation are unbelievably good and easy to understand.

  • @dmitricherleto8234
    @dmitricherleto8234 2 года назад

    Best java teacher I've ever had.

  • @natnaelhaftu9283
    @natnaelhaftu9283 11 месяцев назад

    i havemore than a couple of videos to understand casting, but i found yours so clear , thanks jo

  • @rw4564
    @rw4564 8 месяцев назад

    this guy always makes subjects easy and fun to learn

  • @redblade79x
    @redblade79x 2 года назад

    I’m a relatively new C# programmer and even though this video was explained in Java it made PERFECT sense to me. Great job!

  • @aileenchan3741
    @aileenchan3741 Год назад +1

    This video is a life saver for upcasting and downcasting. Thank you!!

  • @felipeiideaustria8696
    @felipeiideaustria8696 Год назад

    Thank u you are saving my tomorrow exam and helping me understand the things my teacher couldnt, ive seen 4 videos in the last hour

  • @sanghamitrabhowmick6674
    @sanghamitrabhowmick6674 2 года назад

    It was one of the best explanations about topcasting. Thank you so much for posting!!!

  • @lr5648
    @lr5648 2 года назад +2

    A difficult topic explained in such a simple way. Great video! Thanks bud!

  • @BaldChimpanzee
    @BaldChimpanzee 2 года назад

    Hey John! Thank you so much for your videos and course on the website its 200% worth it, I was so tired of these Indian accent guys, was barely able to understand anything, but with your explaination I finally get it all!

  • @gabrielfono844
    @gabrielfono844 Год назад

    as new backend engineer, I really enjoy this project
    love from Virginia

  • @lenalyman9526
    @lenalyman9526 6 месяцев назад

    I like these videos. They have been helping me a lot lately :)

  • @patrick8622
    @patrick8622 Год назад +1

    6:03 The type of variable determines which method you can call. The specific type of object which the variable is referring to determines which specific implementation of that method will be used

  • @khasannishanov5830
    @khasannishanov5830 2 года назад

    thanks for such a clear and positive explanation from Uzbekistan

  • @SoD_Stunning
    @SoD_Stunning Год назад

    Damn, it's so clear now. The polymorphism. Thank you, John.

  • @oneilobi822
    @oneilobi822 2 года назад

    nice tutorials from him in java. he teaches with simple and understanding examples.
    keep up the good job.

  • @alvinchipmunk7279
    @alvinchipmunk7279 3 года назад

    John, you are the best! Big respect to you from Russia!)

  • @pstlvictoras
    @pstlvictoras 2 года назад

    I love your channel as a java programmer, I have learned a lot of new things. Thanks!

  • @ryvikun4325
    @ryvikun4325 10 месяцев назад

    very clear explanation with the right amount of pacing, love it!, great video thanks for helping me understand!

  • @ness_cek
    @ness_cek 3 года назад

    This saved mee thank you so much!! Been re-reading the notes given by my lecturers and couldn't wrap my head around it. This video made is so easy to understand!

    • @smrtfasizmu6161
      @smrtfasizmu6161 2 года назад

      I had the same impression when I learned this a couple of months ago. The book that I was reading explained it so poorly and then I watched this video and suddenly I understood upcasting and downcasting while also wondering how could I ever not understand this.

  • @anujtiwari6949
    @anujtiwari6949 Год назад

    Thanks, This concept was very confusing for me but you have explained beautifully.

  • @georgegn6534
    @georgegn6534 Год назад

    I have an exam in 14 hours this is really helpful!

  • @suponjubobu5536
    @suponjubobu5536 2 года назад

    6:02 summarizes everything pretty nicely.

  • @Tuxon24rus
    @Tuxon24rus 3 года назад

    I love that you put extra tips and hints for beginners, let alone explaining naming conventions and providing useful code style notes in your videos.
    I was wondering misconception of what basic concept/topic of Java is more common among Intern/Junior level programmers in your opinion?
    Thank you!

  • @dudeiknowman
    @dudeiknowman Год назад +1

    Super helpful. Thank you!

  • @mohamedelmouktafi7557
    @mohamedelmouktafi7557 3 года назад

    Simpliest explaining method i've ever seen , thanks sir keep up 👍

  • @perox1982
    @perox1982 2 года назад

    I love your channel, is my favorite. This summer hope takes yours Java course asap.

  • @Mohammad_C137
    @Mohammad_C137 Месяц назад

    Wow that was amazing john, Thank you so much.

  • @rickmemmer5625
    @rickmemmer5625 2 года назад +1

    As top-notch as it gets. Just exceptional work. Thanks a million! :o)

  • @ihsannuruliman3656
    @ihsannuruliman3656 3 года назад

    Hi John, I really love your videos it really fresh up my mind on things I forget on Java.

  • @vineethamuralidhar5176
    @vineethamuralidhar5176 2 года назад

    Your explanation is crystal clear!

  • @ניצןבשן
    @ניצןבשן 3 года назад

    This video really helps understand what downcasting and upcasting do! Thnx a lot :D

  • @spooki6637
    @spooki6637 3 года назад

    GREAT TUTORIAL!!!!!! THANK YOU SO MUCH I LEARNED A LOT FROM THIS CHANNEL.

  • @AVINASHRANJAN21
    @AVINASHRANJAN21 3 года назад

    I am having 8+ year of exp bt still i love to watch ur videos even i know all the point which u covered. Great

  • @peril7531
    @peril7531 Год назад

    found my uni lecture on this a bit difficult to understand but this video laid it out so clearly!!

  • @borisvasilev4893
    @borisvasilev4893 Год назад

    Thanks, your videos are incredible! (Comment for the support because of your support!)

  • @matiasmoresi5040
    @matiasmoresi5040 2 года назад

    Hey John, thanks for sharing so your knowledge! Loving your channel

  • @aajbakeraajbaker8444
    @aajbakeraajbaker8444 2 года назад

    This is a really good explanation, it helped me get through learning this pretty fast.

  • @asyakatanani8181
    @asyakatanani8181 3 года назад

    I enjoyed, I learned way more than merely "something", I subscribed and I am surprised why I didn't meet you before...

  • @jaaeamor7901
    @jaaeamor7901 2 года назад

    The instanceof part was soooo cool 🤯

  • @RokayaId-ElMouedden
    @RokayaId-ElMouedden 8 месяцев назад

    so clear, perfect explanation

  • @front-endfatih4030
    @front-endfatih4030 3 года назад

    Love your videos John, you are not bad at explaining topics that I need more clarification on.

  • @bausantodomingo6766
    @bausantodomingo6766 Год назад

    Great video John! The explanation was clear and engaging! Thank you!

  • @nasirnesirli5446
    @nasirnesirli5446 2 года назад

    Great explanation! I have finally understood the hardest part of OOP for me. Thank you.

  • @odaakeenya
    @odaakeenya 2 года назад

    Long live to genius people like you. you are million times better than my prof.

  • @adityendrapratapsingh4628
    @adityendrapratapsingh4628 2 года назад

    massive respect sir I've been struggling with this but you finally cleared it for me. thank you so much

  • @macharla.saicharan.2285
    @macharla.saicharan.2285 2 года назад

    Frankly, This video cleared all my doubts regarding object casting ..Thanks john for this amazing video...and I request you to create a complete java tutorials playlist for beginners so that we can go with a flow..try considering this request :)

  • @hectorgil3495
    @hectorgil3495 3 года назад

    Thank you , greetings from Costa Rica !

  • @carina.zip2002
    @carina.zip2002 2 года назад

    You teach better than my professor, thank you so much!

  • @user679jk7
    @user679jk7 Год назад

    What a fantastic explanation!

  • @yourlinuxguy
    @yourlinuxguy Год назад

    Really exactly the video that I needed.

  • @zainabedin9842
    @zainabedin9842 3 года назад

    This video is the best explanation for this topic. Thanks.

  • @liw4972
    @liw4972 Год назад

    You make everything a piece of cake. Thanks for sharing with us

  • @ralphrgore
    @ralphrgore 2 года назад +2

    Hey John, thank you so much for sharing these free classes. You are awesome. In the meantime, can I ask to share the codes in this video and others in NotePad or any other relevant formats under the video(s)? Your reply is highly appreciated.

  • @PieMongo
    @PieMongo 3 года назад +1

    Are you also playing the drums? You really are the coolest java channel on this platform

    • @CodingWithJohn
      @CodingWithJohn  3 года назад +1

      Yep! Just self-taught and play at home, not in a band or anything. But it's one of my favorite things to do.

    • @jvsnyc
      @jvsnyc 3 года назад

      @@CodingWithJohn I don't want to work, I want to bang on a drum all day....I don't want to play, I want to bang on a drum all day....the funny thing is that Todd Rundgren was pretty obsessive, recorded whole albums with himself playing all the instruments, writing everything, doing all the engineering and editing and producing...also a computer programmer. So, that song is triply hysterical.

  • @codelibre5651
    @codelibre5651 3 года назад

    Fantastic tutorial - simple and easy to follow (and it works for C#).

  • @BrunoHenrique-vd1ry
    @BrunoHenrique-vd1ry Год назад

    Very nice vídeo! i´m from brazil and you video helped me so much, thanks! :)

  • @cagla3360
    @cagla3360 2 года назад

    Thank you so much John! Learned a lot as always :)

  • @joelin9801
    @joelin9801 2 года назад

    (I'm using this comment for note-taking)
    Biggest takeway:
    the type of the variable determines which methods you can call
    but the specific type of the object that this variable is referring to determines which specific implementation of that method will be used when the method is called

  • @leandroacevedo3339
    @leandroacevedo3339 2 года назад

    Thanks a lot! I ended up learning OOP concepts with Java since I made the mistake to start learning programming with Dart...
    Anyway, very well explained, keep it up!

  • @siphesilekhumelo8884
    @siphesilekhumelo8884 Год назад

    Bro just made it look super easy

  • @bokas5
    @bokas5 Год назад

    Exactly what I needed! Thank you :)

  • @Alibeee87
    @Alibeee87 3 года назад

    So much clarity provided, makes way more sense than my book's definition of downcasting: "If a program needs to perform a subclass specific operation on a subclass object referenced by a superclass variable (me: uhhhh..what?), the program must first cast a superclass reference to a subclass reference(me: .......)." 😂 I would much rather watch your video instead. Thank you!

    • @lookupverazhou8599
      @lookupverazhou8599 3 года назад

      Programmers aren't very good at english.

    • @smrtfasizmu6161
      @smrtfasizmu6161 2 года назад +1

      This was more or less how it was explained in the book that I was reading a couple of months ago. Then I watched this video a couple of months ago and I finally understood upcasting and downcasting!
      John is such a great teacher.
      On the other hand, I feel like people who are writing this book are trying not to be understood by learners. Now, I understand the sentence that you quoted, but you can only understand that sentence if you already understand downcasting and upcasting! Which defeats the purpose of this sentence which was supposed to explain downcasting and upcasting to learners who don't already understand what it means. I find it similar to Wikipedia pages about math and physics. You can only understand them if you already understand the topic. These things are made as a refreshers not as a learning tool. It is a shame that such poor explanations enter learner books (which they often times do unfortunately).

  • @ddp1863
    @ddp1863 2 года назад

    Great video John helped me loads thanks

  • @JuanManuelRizzi
    @JuanManuelRizzi 10 месяцев назад

    I love these explanations! Thanks Sir!!!

  • @lj123-g9d
    @lj123-g9d 2 года назад

    This was a bit complex topic. Well explained sir 👏👏

  • @Jhones9696
    @Jhones9696 10 месяцев назад +1

    I was having a hard time trying to understand this casting thing. You just saved some of my brain cells from bursting into flames. :'v

  • @amalelayeb874
    @amalelayeb874 2 года назад

    Thank u for your time ❤I really did learn 🥰