Was looking for C# but this was very relavent regardless. I really really like the stack and heap insights in the tutorial as it helps understand whats *really* going on
01:10 does not Lion class inherit controlTemp() as well? If we talk about general inheritance as it is. So, in total Lion method has access to next method (via inheritance) eat() - from Animal sleep() - from Animal controlTemp() - from mammal and one own unique method roar() ear() @overridden
Yes. When you cast an object, you aren't changing any data. You are just "making promises" to the compiler that it is pointing at an object of the type you are casting it as.
@@BillBarnum I watched it but am still a little confused. In the classes Lion extends mammal, mammal extends animal so wouldn't Lion jen = new Lion() work without having to type cast any methods? Basically I am confused when you use Animal jen in place of Lion jen because they seem to do the same thing.
@@kakashi99908 Let's take two variables: Animal alex = new Lion(); Lion jen = new Lion(); The methods available to alex are only those that are declared in Animal. So we could do alex.eat() and alex.sleep(), but we couldn't do alex.roar(), because the alex variable is an Animal and there is no roar() in the Animal class. On the other hand, the jen variable is declared as a Lion. Lion classes have the roar() method, so we COULD do jen.roar() The variable type determines what methods are available. The object type determines what version of the method is run.
You can't override the sleep() function in the Animal class because that's where it originates. You can override sleep in a subclass that would otherwise inherit sleep() Does that answer your question?
📌 Subscribe For The Latest Videos: bit.ly/36H70sy 📌
.
💻 All Java Tutorials: bit.ly/JavaTutorialsTH-cam 💻
.
🤖 Learn Java In 3 Hours: bit.ly/JavaIn3Hours 🤖
OH MY GOODNESS THIS IS THE CLEAREST EXPLANATION OF UPCASTING THANK YOU
Awesome man. A visual representation always helps in better understanding. Keep posting more videos.
Indeed, this video is one of the best explanation on casting of objects out there!!!
Thanks for the feedback. I'm glad you liked the video!
Thank you bill been stuck here for a long time now... downcasting is clear
Legendary video on the subject. The best've I found on TH-cam so far!
Wow, thanks!
Exactly what I needed to know at this moment. Thanks, Bill!
from India, watching it the night before exam. thanks a lot for making a short easy to understand video.
Good luck on your exam!
After one day trying to understand Casting and finally just 5 minutes explained very clearly to be ok ! thanks !!!
Thanks for the feedback Amine. I'm glad you like the video.
I am really thankful for this tutorial. Keep up the good work!
Thanks for the feedback! I'm glad that you found it useful.
I love you Bill, finally a full tutorial with all possible examples.
really informative, and perfect explanation, thanks bill.
Finally someone who explains correctly this topic. Thank you Sir.
Thanks for watching and commenting, Alejandro.
Thanks man … Great explanation
That is a great explanation... Thanks for the video!
Was looking for C# but this was very relavent regardless. I really really like the stack and heap insights in the tutorial as it helps understand whats *really* going on
Thanks for the feedback!
01:10 does not Lion class inherit controlTemp() as well? If we talk about general inheritance as it is.
So, in total Lion method has access to next method
(via inheritance)
eat() - from Animal
sleep() - from Animal
controlTemp() - from mammal
and one own unique method
roar()
ear() @overridden
Really helpful video man💯💯💯. keep uploading more videos .
Thank you so much Bill ❤❤
Exactly what i needed. Thanks for this great content!
it is midnight and will be writing an important exam at 8am :D after this video i finally got the object casting thank you haha :D
Good luck on your exam!
Thank you sir! God bless you
Thanks for the video! Very clear and to the point presentation!
Thanks for the feedback, OBIT.
thanks you from morocco
really good!
perfect explanation
thanks a lot
Amazing explanation. Thank you.
Brilliant explanation!
Thanks for watching and commenting, João!
Thank you so much for this awesome tutorial!
Glad it was helpful, Rhoad!
this video is awesome - thank you so much
Exactly what I needed before my exam!
you're the best, keep it up
Very good explaination sir love ❤️ from India 🇮🇳
Excellent, helped a lot. Thank you!
OMGGGG!!! You are a genius!!! It's awesome =)
Thanks for watching and commenting!
Thanks a lot!
Thanks a lot! Clear enough:)
Very good explanation i got my points
Thanks for watching and commenting.
amazing explanation
Glad you liked it
Thank you, this really helps
Great video
Thanks a looooooot. You are great.
Thanks for the feedback Serhat. I'm had you liked the video!
Thank you!
Thanks for the feedback. I'm glad you found it helpful.
Do these same concepts hold true with the fields for the classes when upcasting and downcasting? This video only covers the interactions with methods.
Yes, it would work the same way with fields.
Bill Barnum Thank you very much it all makes since now.
Loved it Thanks Much
Thanks for the feedback!
Thank you my good sir !!!!
Thanks for the comment, IluSsIoNnN.
Mutilple times of casting,by using single object is possible or not?
Yes. When you cast an object, you aren't changing any data. You are just "making promises" to the compiler that it is pointing at an object of the type you are casting it as.
Thank you so much !! awesome explanition
great video
Thanks for watching and commenting, Lazry!
excellent!
Thanks for the feedback Gino.
Thanks.👍
Thank you so much
Thanks for watching and commenting Ramzi!
Good video
v.good sir
So what are the limitations of doing: Lion jen = new Lion()?
I recommend my video on Polymorphism. I think it will answer your question:
th-cam.com/video/cUh3Q9l3Q-0/w-d-xo.html
@@BillBarnum I watched it but am still a little confused. In the classes Lion extends mammal, mammal extends animal so wouldn't Lion jen = new Lion() work without having to type cast any methods?
Basically I am confused when you use Animal jen in place of Lion jen because they seem to do the same thing.
@@kakashi99908
Let's take two variables:
Animal alex = new Lion();
Lion jen = new Lion();
The methods available to alex are only those that are declared in Animal. So we could do alex.eat() and alex.sleep(), but we couldn't do alex.roar(), because the alex variable is an Animal and there is no roar() in the Animal class.
On the other hand, the jen variable is declared as a Lion. Lion classes have the roar() method, so we COULD do jen.roar()
The variable type determines what methods are available. The object type determines what version of the method is run.
Animal jen = new lion()
Jen. Controltemp() , a valid statement??
i cant hear the sentence at 4:02. can anybody tell me pls.
"This is legal because we are assuring the compiler that Jen is, in fact, pointing at a Lion type object. "
@@BillBarnum thank you so much sir for explaining, I misheard is, in fact to "isn't fact ".
ty so much
I have a serious confusion. Here it is:
Animal
You can't override the sleep() function in the Animal class because that's where it originates.
You can override sleep in a subclass that would otherwise inherit sleep()
Does that answer your question?
very descriptive
Thanks for watching and the comment, Aashish!
What a fucking amazing description lol
Good for mugging up only
Lifesaver
How to cast string to user defined object type
Here are a couple of examples:
Object x = new String("test 123"); //upcasting example
String y = (String)x; //downcasting example
lion l = new lion();
This is valid
So will it come under downcasting?
Good question.
In that case, the variable and object type are the same, so it isn't casting.
@@BillBarnum ok thanks
thanks...
For more visit: th-cam.com/video/wbrWpt--cgw/w-d-xo.html
cool.
Explained an hour of university lecture content in just under 6 minutes and so much better. Maybe I should pay you instead?
Thanks for the comment, Simon.
I'm glad you thought it was a useful video!
poor joe
That's what happens when you don't follow the rules of Java. 🙂
tx G
+
Good job bro
Thanks
@@BillBarnum you are welcome sir. You've saved my life in college.
Thank you!!
Great video
Thanks for checking out the video!
THANK YOU !
Awesome video
Thanks for watching and commenting, Anant!
great. thanks!
Thanks for commenting, Maha!