Java Video Tutorial 14

Code From Video:

Best Java Book :

In this Java video tutorial I cover Polymorphism, Inheritance, Protected, Final, Instanceof and a bunch more.






33 responses to “Java Video Tutorial 14”

  1. Rakesh N Avatar

    You are AMAZING DUDE!

  2. NatMesh Avatar

    You are the man, amazing tutorial! so much learned in such a small amount of time, thank you!!!

  3. clerp Avatar

    Why does your voice make me think you have a beard?

  4. zoilo garingan Avatar

    This tutorial was obsolete

  5. Ali The Flying Tiger Avatar

    if class cats override a method of its superclass Animal that's polymorphism?

  6. SlooshPand Avatar

    His voice like theradbrad lol

  7. Kevin Rivas Avatar

    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");


    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.

  8. Aaron Benderman Avatar

    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!

  9. Ein Hacker-Typ Avatar

    Superb explanation, thanks

  10. DARPAN ANEJA Avatar


  11. element74 Avatar

    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.

  12. element74 Avatar

    you may have just given the best explanation and example of polymorphism on youtube or internet, lol.

  13. believe theUnbelievable Avatar

    how can i call both super and this constructor in a constructor in derived class

  14. S J Avatar

    How does =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?

  15. Storystein Avatar

    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.

  16. Evgeni Kuzmov Avatar

    Tuna ? I've seen this before lol

  17. Evgeni Kuzmov Avatar

    newName is an object and changeName is a method, right?

  18. pegz soltani Avatar

    How do we reach the walk around method which is in the parent class? By type casting randAnimal to Animals?

  19. Zaidhaan Hussain Avatar

    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?

  20. omer marom Avatar

    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?

  21. Youssef Samwel Avatar

    Derek, what is the purpose of polymorphism and how can i use it.

  22. Zsófia Princz Avatar

    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'…

  23. Olav Sørlie Avatar

    Best programmer on youtube 🙂

  24. Johnny Batafljeska Avatar

    Can someone PLEASE EXPLAIN at the begining

    protected final void changeName(String newName){ = newName;


    protected final String getName(){

    why do we need this? what does it do?

  25. Amit Singh Avatar

    how it knows that randAnimal is a cat?

  26. Justin Lee Avatar

    I'm only 11 years old, but should I be able to understand your videos? because I don't

  27. CAROLINE Avatar

    I appreciate this tutorials.
    but I don't get this one.

    Animal tabby = new Cat("Tabby", "Salmon", "Ball");

  28. Deepak Kumar Avatar

    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.

  29. David Brown Avatar

    Thank you for making my life easier! You videos and site are awesome!

Leave a Reply

Your email address will not be published. Required fields are marked *