Code From Video:
Best Java Book :
In this Java video tutorial I cover Polymorphism, Inheritance, Protected, Final, Instanceof and a bunch more.
Code From Video:
Best Java Book :
In this Java video tutorial I cover Polymorphism, Inheritance, Protected, Final, Instanceof and a bunch more.
by
Tags:
You are AMAZING DUDE!
You are the man, amazing tutorial! so much learned in such a small amount of time, thank you!!!
Why does your voice make me think you have a beard?
This tutorial was obsolete
if class cats override a method of its superclass Animal that's polymorphism?
great video thnx
His voice like theradbrad lol
Does Java's interpreter know to use method .walkAround from subclass Cats because object tabby, which is associated with Cats, was passed to method acceptAnimals, and since .walkAround is in that method (where tabby was passed) the interpreter says "Well, tabby is associated with Cats, therefore I shall use method .walkAround from that subclass (Cats)"?
That would explain how a Tester class would chose what .walkAround method to chose from if super class Animals had other subclasses with the same method "walkAround" for example Dog, Fish, Unicorn.
So if I wanted to utilized .walkAround method from subclass Unicorn, it would look something like this?
Animals patty = new Unicorns("Patty", "humans", "ball");
acceptAnimal(patty);
output:
Patty
humans
gallop
Although there are now three classes, the interpreter knows to use Unicorn's method walkAround() because patty was associated with Unicorn and there is a method in Unicorn with the same name and because .walkAround was found in acceptAnimal's braces which again passed object patty?
So in other words that is how .walkAround would be morphed into any of the subclasses' .walkAround?
Sorry this is so long. Polymorphism sounds complicated and intimidating and want to ensure I grasp it. I'm also bad with grammar, so I understand if you do not want to go over this.
What did you mean by that you have to pass tabby? What does pass mean? 8:02 :edit: Never mind, I just had to re watch to understand it lol. My bad and thank you for these great videos!
Superb explanation, thanks
youRockGuruJi;
hatsOffToYou;
lotsOfLove;
12:13 you explained something that I wish you could clarify. You said:
"The function instanceof checks to see if an object is an instance an object OR has access to the methods/fields inside an object."
Correct me if I'm wrong. Instance of another object does not mean you have access to their methods/fields, correct? Because for example, the object, tabby, could not access exclusive Cats methods/variables even though it was an instance of Cats. If this is correct, then the function instanceof is checking for 2 different conditions.
Is tabby an instance of Animal and an instance of Cats? Because of the line
Animal tabby = new Cats(); ?
I thought the definition of instance is a variable that stores information that is called from a constructor. From the example I just wrote, tabby stores information called from the constructor, Cats(). This terminology confuses me, because how is tabby an instance of Animal?
I would accept that tabby is an Animal and a Cat, but tabby is not an instance of Animal, if my definition is correct.
you may have just given the best explanation and example of polymorphism on youtube or internet, lol.
how can i call both super and this constructor in a constructor in derived class
How does this.name =newName; work in the accessing the name of the Cat, despite the fact that it is declared in a method called getName() in Animals class? Any more explanation on how "this", works?
This video now has exactly 100.000 views.. which is so pleasing to look at.
But thanks for the explanation, it's hard to understand it all as a beginner.
Tuna ? I've seen this before lol
newName is an object and changeName is a method, right?
How do we reach the walk around method which is in the parent class? By type casting randAnimal to Animals?
In some codes i see @Override in it, why is it there? cant we just simply do it like you showed without writing the @Override?
great tutorial, but i don't get one thing.
what do you achieve by creating an object like this : Animals tabby = new Cats("tabby", "salmon", "ball"); that you don't achieve by creating it like this : Cats tabby = new Cats("Tabby", "salmon", "ball"); ?
what is the advantage of declaring an object with the super class and the sub class over only declaring it with the sub class?
doesn't the Cats class already contain the fact that it is a sub class of the Animals class in it?
Thanks!
Derek, what is the purpose of polymorphism and how can i use it.
Hi Derek! I love your tutorials very much. For me it was hard to understand 'casting' when it was explained in the context of 'Cats'…
Best programmer on youtube 🙂
Well Done.
how it knows that randAnimal is a cat?
I'm only 11 years old, but should I be able to understand your videos? because I don't
You are great
I appreciate this tutorials.
but I don't get this one.
Animal tabby = new Cat("Tabby", "Salmon", "Ball");
hi derek. I had question related to polymorphism. Why would randanimal which is an instance of animal although initialized with cat will hold the "ball" string and it is definitely holding the string "ball" since after casting to a cats class we can see it. Animal has no field that can store it.
Thank you for making my life easier! You videos and site are awesome!
Leave a Reply