Upcasting and Downcasting in Java - Full Tutorial

  Рет қаралды 169,293

Coding with John

Coding with John

2 жыл бұрын

Learn about Upcasting and Downcasting in Java! Full tutorial with concrete examples.
In Java, upcasting and downcasting are used along with method overriding to do some really cool things. But what exactly is upcasting, what is downcasting, and how do you use them in your Java programs?
When can you upcast, and when can you downcast? What do you need to know to use upcasting and dowcasting safely? We'll talk about all of that and more beginner-friendly Java tutorial video.
Learn or improve your Java by watching it being coded live!
Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
Let me know what else you'd like to see!
Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
📕 THE best book to learn Java, Effective Java by Joshua Bloch
amzn.to/36AfdUu
📕 One of my favorite programming books, Clean Code by Robert Martin
amzn.to/3GTPVhf
🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
www.audibletrial.com/johnclean...
🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
bit.ly/3QPNGko
📹Phone I use for recording:
amzn.to/3HepYJu
🎙️Microphone I use (classy, I know):
amzn.to/3AYGdbz
Donate with PayPal (Thank you so much!)
www.paypal.com/donate/?hosted...
☕Complete Java course:
codingwithjohn.thinkific.com/...
codingwithjohn.com

Пікірлер: 334
@arturmelo3681
@arturmelo3681 9 ай бұрын
the "meow" at 5:05 was the best part of the video, thanks john
@callmesej6935
@callmesej6935 2 жыл бұрын
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 2 жыл бұрын
hvordan var det?
@jospherstudies
@jospherstudies 2 жыл бұрын
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 жыл бұрын
I have mine tomorrow, and I'm learning more here than I have in class.
@Christian-ry3ol
@Christian-ry3ol 2 жыл бұрын
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.
@findlestick
@findlestick 2 жыл бұрын
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 жыл бұрын
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 🙌🏼
@robert4598
@robert4598 2 жыл бұрын
What the f... those are the best explanations I've heard so far. That sums up 3 hours of Uni lecture in 10 minutes!
2 жыл бұрын
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!!!
@renzotorr537
@renzotorr537 2 жыл бұрын
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 2 жыл бұрын
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 жыл бұрын
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 Жыл бұрын
Thank you for sharing that. Appreciate it!
@KAROMII1
@KAROMII1 2 жыл бұрын
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 Жыл бұрын
I know the feeling -- and this video just blew that door wide open. What a relief!! :o)
@MishaKoroliov
@MishaKoroliov 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!
@SoftwareTestSolutions
@SoftwareTestSolutions 2 жыл бұрын
Loved this again! My 9 years old son is watching you on KZfaq and practicing the Java.
@lookupverazhou8599
@lookupverazhou8599 2 жыл бұрын
@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.
@josephthecreator
@josephthecreator 2 жыл бұрын
HANDS DOWN the absolute best channel I've found regarding Java tutorials and explanations. Thank you John!
@LuckyMakhado
@LuckyMakhado 2 жыл бұрын
First time KZfaq 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.
@front-endfatih4030
@front-endfatih4030 2 жыл бұрын
Love your videos John, you are not bad at explaining topics that I need more clarification on.
@smrtfasizmu6161
@smrtfasizmu6161 2 жыл бұрын
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.
@aileenchan3741
@aileenchan3741 Жыл бұрын
This video is a life saver for upcasting and downcasting. Thank you!!
@Tuxon24rus
@Tuxon24rus 2 жыл бұрын
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!
@natnaelhaftu9283
@natnaelhaftu9283 4 ай бұрын
i havemore than a couple of videos to understand casting, but i found yours so clear , thanks jo
@manarsalem1685
@manarsalem1685 2 ай бұрын
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 💞
@chiranjibdash1843
@chiranjibdash1843 2 жыл бұрын
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.
@lr5648
@lr5648 2 жыл бұрын
A difficult topic explained in such a simple way. Great video! Thanks bud!
@halilibrahimustun50
@halilibrahimustun50 2 жыл бұрын
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 :)
@dominiqueradtke1262
@dominiqueradtke1262 5 ай бұрын
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!!
@adityendrapratapsingh4628
@adityendrapratapsingh4628 2 жыл бұрын
massive respect sir I've been struggling with this but you finally cleared it for me. thank you so much
@sydneygoeury6102
@sydneygoeury6102 2 жыл бұрын
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 жыл бұрын
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.
@sabari360
@sabari360 2 жыл бұрын
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.
@BGP_23
@BGP_23 8 ай бұрын
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.
@beat-fustudio8910
@beat-fustudio8910 2 жыл бұрын
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 !
@hotcupofbeans
@hotcupofbeans 2 жыл бұрын
These videos are great 👍 love the way you explain things. Thanks!
@codelibre5651
@codelibre5651 2 жыл бұрын
Fantastic tutorial - simple and easy to follow (and it works for C#).
@ihsannuruliman3656
@ihsannuruliman3656 2 жыл бұрын
Hi John, I really love your videos it really fresh up my mind on things I forget on Java.
@pstlvictoras
@pstlvictoras 2 жыл бұрын
I love your channel as a java programmer, I have learned a lot of new things. Thanks!
@nasirnesirli5446
@nasirnesirli5446 2 жыл бұрын
Great explanation! I have finally understood the hardest part of OOP for me. Thank you.
@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!
@smrtfasizmu6161
@smrtfasizmu6161 2 жыл бұрын
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.
@sanghamitrabhowmick6674
@sanghamitrabhowmick6674 Жыл бұрын
It was one of the best explanations about topcasting. Thank you so much for posting!!!
@matiasmoresi5040
@matiasmoresi5040 2 жыл бұрын
Hey John, thanks for sharing so your knowledge! Loving your channel
@user-rw4lr7pl2o
@user-rw4lr7pl2o 8 ай бұрын
The best enjoyable way to learn Java is your lovely channel. I appreciate your efforts.
@bausantodomingo6766
@bausantodomingo6766 Жыл бұрын
Great video John! The explanation was clear and engaging! Thank you!
@ness_cek
@ness_cek 2 жыл бұрын
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.
@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!
@spooki6637
@spooki6637 2 жыл бұрын
GREAT TUTORIAL!!!!!! THANK YOU SO MUCH I LEARNED A LOT FROM THIS CHANNEL.
@rickmemmer5625
@rickmemmer5625 Жыл бұрын
As top-notch as it gets. Just exceptional work. Thanks a million! :o)
@mohamedelmouktafi7557
@mohamedelmouktafi7557 2 жыл бұрын
Simpliest explaining method i've ever seen , thanks sir keep up 👍
@Cablur
@Cablur 11 ай бұрын
Mate, what a great and fully comprehensive video about this subject on which I smacked my head at the wall the whole day ❤
@emreibrahim8504
@emreibrahim8504 11 ай бұрын
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 2 жыл бұрын
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 жыл бұрын
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 8 ай бұрын
They're both OOP languages so a lot of the underlying concepts are the same as other "C" based ones.
@ryvikun4325
@ryvikun4325 3 ай бұрын
very clear explanation with the right amount of pacing, love it!, great video thanks for helping me understand!
@asaphferreira6448
@asaphferreira6448 5 ай бұрын
Sir, your explanation is amazing. Thank you a lot.
@aajbakeraajbaker8444
@aajbakeraajbaker8444 Жыл бұрын
This is a really good explanation, it helped me get through learning this pretty fast.
@lynnwai152
@lynnwai152 3 ай бұрын
The best explanation of casting ever. Thanks, John.
@zainabedin9842
@zainabedin9842 2 жыл бұрын
This video is the best explanation for this topic. Thanks.
@user-sz9nf9lh6q
@user-sz9nf9lh6q 2 жыл бұрын
This video really helps understand what downcasting and upcasting do! Thnx a lot :D
@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🤩
@hgatl
@hgatl 2 жыл бұрын
you made it super simple to understand, thank a lot
@SoD_Stunning
@SoD_Stunning Жыл бұрын
Damn, it's so clear now. The polymorphism. Thank you, John.
@ddp1863
@ddp1863 2 жыл бұрын
Great video John helped me loads thanks
@vinayakrodd8837
@vinayakrodd8837 10 ай бұрын
Thank you John for your explanation on Casting thank you ...
@user-xj6uo3mn3i
@user-xj6uo3mn3i 4 ай бұрын
I love these explanations! Thanks Sir!!!
@rw4564
@rw4564 Ай бұрын
this guy always makes subjects easy and fun to learn
@dudeiknowman
@dudeiknowman Жыл бұрын
Super helpful. Thank you!
@cagla3360
@cagla3360 Жыл бұрын
Thank you so much John! Learned a lot as always :)
@gabrielfono844
@gabrielfono844 Жыл бұрын
as new backend engineer, I really enjoy this project love from Virginia
@bokas5
@bokas5 Жыл бұрын
Exactly what I needed! Thank you :)
@amalelayeb874
@amalelayeb874 2 жыл бұрын
Thank u for your time ❤I really did learn 🥰
@mahmoudalarebi9174
@mahmoudalarebi9174 Жыл бұрын
Thanks alot for the Help John
@anujtiwari6949
@anujtiwari6949 5 ай бұрын
Thanks, This concept was very confusing for me but you have explained beautifully.
@vineethamuralidhar5176
@vineethamuralidhar5176 2 жыл бұрын
Your explanation is crystal clear!
@peril7531
@peril7531 Жыл бұрын
found my uni lecture on this a bit difficult to understand but this video laid it out so clearly!!
@RokayaId-ElMouedden
@RokayaId-ElMouedden Ай бұрын
so clear, perfect explanation
@gautamanimesh8909
@gautamanimesh8909 2 жыл бұрын
Thanks for the explanation! Grateful to be a subscriber!💯💯
@perox1982
@perox1982 2 жыл бұрын
I love your channel, is my favorite. This summer hope takes yours Java course asap.
@khasannishanov5830
@khasannishanov5830 2 жыл бұрын
thanks for such a clear and positive explanation from Uzbekistan
@yourlinuxguy
@yourlinuxguy Жыл бұрын
Really exactly the video that I needed.
@user-vg3qn8xt3c
@user-vg3qn8xt3c 8 ай бұрын
you explained exactly what I needed! tnx
@PappyTrading
@PappyTrading 2 жыл бұрын
Your videos are very well done. Thank you.
@ronakpatel9109
@ronakpatel9109 Жыл бұрын
You are awesome, you have cleared my doubt Thank you. ❤
@lenalyman9526
@lenalyman9526 12 күн бұрын
I like these videos. They have been helping me a lot lately :)
@mehdiakbari7082
@mehdiakbari7082 2 жыл бұрын
hi John thanks alot for your tutorial they are realy good and easy to underestand.
@sharmfernando3040
@sharmfernando3040 8 ай бұрын
Nicely explained!! Thank you
@user679jk7
@user679jk7 Жыл бұрын
What a fantastic explanation!
@rajachemali7977
@rajachemali7977 2 жыл бұрын
Great video as always. Thank you sir!
@borisvasilev4893
@borisvasilev4893 Жыл бұрын
Thanks, your videos are incredible! (Comment for the support because of your support!)
@overspyx44
@overspyx44 2 жыл бұрын
Great video! Very good and simple explanation!
@dmitricherleto8234
@dmitricherleto8234 2 жыл бұрын
Best java teacher I've ever had.
@imadabid1672
@imadabid1672 2 жыл бұрын
Thanks ! This video helped me a lot.
@135_afshashaikh2
@135_afshashaikh2 Жыл бұрын
Thank you for the explanation.
@asyakatanani8181
@asyakatanani8181 2 жыл бұрын
I enjoyed, I learned way more than merely "something", I subscribed and I am surprised why I didn't meet you before...
@spd5696
@spd5696 2 жыл бұрын
It was a good explanation, really helpful.Thanks
@macharla.saicharan.2285
@macharla.saicharan.2285 Жыл бұрын
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 :)
@Lileminem93
@Lileminem93 2 жыл бұрын
That really helped, 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
@shubhamkotnala6743
@shubhamkotnala6743 2 жыл бұрын
Goes straight to my brain 👍
@moncefarajdal4582
@moncefarajdal4582 2 жыл бұрын
Well explained. Thank you so much
@ralphgore3543
@ralphgore3543 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.
@irenenash8401
@irenenash8401 Жыл бұрын
That is really helpful so thank you!😃
@inoobbeyt1031
@inoobbeyt1031 Жыл бұрын
that instanceof operator is new to me nice i learn new thing
@user-tf6no2wr2u
@user-tf6no2wr2u Жыл бұрын
Thank you so much, John❤😊
@Play_Streams
@Play_Streams 2 жыл бұрын
Great lesson. Thank you!
@savagepeng
@savagepeng Жыл бұрын
Perfect explanation!
@hectorgil3495
@hectorgil3495 2 жыл бұрын
Thank you , greetings from Costa Rica !
Super Keyword in Java Full Tutorial - How to Use "super"
11:33
Coding with John
Рет қаралды 198 М.
Exception Handling in Java Tutorial
13:20
Coding with John
Рет қаралды 371 М.
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 43 МЛН
#59 Upcasting and Downcasting in Java
6:37
Telusko
Рет қаралды 87 М.
Lambda Expressions in Java - Full Simple Tutorial
13:05
Coding with John
Рет қаралды 718 М.
Generics In Java - Full Simple Tutorial
17:34
Coding with John
Рет қаралды 1 МЛН
Java Strings are Immutable - Here's What That Actually Means
7:06
Coding with John
Рет қаралды 607 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 171 М.
.equals() vs. == in Java - The Real Difference
8:48
Coding with John
Рет қаралды 182 М.
ARRAYLIST VS LINKEDLIST
21:20
Core Dumped
Рет қаралды 54 М.
Java Tutorials || Java OOPS  || 3 Mantras of Object Type Casting || by durga sir
24:27
Java dynamic polymorphism ✨
8:52
Bro Code
Рет қаралды 65 М.
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 43 МЛН