Java Polymorphism Fully Explained In 7 Minutes

Поділитися
Вставка
  • Опубліковано 15 жов 2024
  • Complete Java course: codingwithjohn...
    What does polymorphism mean in Java? So many classes and courses overcomplicate it, but polymorphism is really super simple. We'll talk about what polymorphism means in Java, and go over two different kinds.
    Polymorphism is one of the 4 core concepts of Object-oriented programming languages. And it's such a scary sounding word, but it refers to a simple concept.
    Learn or improve your Java by watching it being coded live!
    Hey, 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 developers.
    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.audibletria...
    🖥️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...
    ☕Complete Java course:
    codingwithjohn...
    codingwithjohn...

КОМЕНТАРІ • 450

  • @Mobin92
    @Mobin92 2 роки тому +22

    You kinda left out the main point of Polymorphism. The conclusion should be that you can store all the different instances (e.g. of Dog, Cat, ...) in Animal variables and it still does the proper thing! Usually you e.g. have a List which contains different animals, and you can just call the eat() function on each element without worrying what type it actually is.

  • @LitchBeats
    @LitchBeats 3 роки тому +564

    This guy is way too underrated 🔥

  • @electronoob7341
    @electronoob7341 3 роки тому +347

    My Univ. professor couldn't explain it to me like this over a whole semester!
    Now here I am understanding it in under 10min.
    Thank you!

    • @King-cv6mn
      @King-cv6mn 2 роки тому +1

      Perhaps you should have come here first

    • @michimarz
      @michimarz Рік тому +5

      John has some very good videos, but this one is kinda disappointing, I'd say. It's not exactly polymorphism what John is explaining here. It's more like he's only describing inheritance. That said, I think you should have listened more carefully to your Professor instead.

    • @techatival
      @techatival Рік тому +3

      "If you can't explain it simply, you don't understand it well enough." - Albert Einstein

    • @Pratik_yadaw
      @Pratik_yadaw Рік тому +2

      maybe bc you love dogs and cats

    • @justspacing9031
      @justspacing9031 Рік тому

      @@michimarz What? Did you even watch the video?

  • @travismaurice6308
    @travismaurice6308 2 роки тому +75

    Dude. You really just saved my entire life. I was having so much trouble understanding how to explain polymorphism and putting it into my own words. You explained it so perfectly in so many ways. Great content!

    • @mmq6525
      @mmq6525 Рік тому +3

      lol entire life? a little dramatic aren't we

    • @smeboo9044
      @smeboo9044 Рік тому +3

      @@mmq6525got somethin’ to prove now do we?

    • @EkThaKingMan
      @EkThaKingMan Рік тому +1

      @@mmq6525 bros got gun to his head by boss as we watch

  • @menaaziz27
    @menaaziz27 3 роки тому +72

    Subscribed!
    with polymorphism also you can always assign a subclass object type to a super class reference type
    like that
    Animal cat = new Cat();
    Animal dog = new Dog();
    Animal a = new Animal();
    Since
    Animal cat = new Cat()
    | |
    | |
    Reference type object type
    Happy coding everyone.

    • @MrSelmanceltiker
      @MrSelmanceltiker 2 роки тому +32

      Actually this is the correct explanation of polymorphism. The video content explains inheritence mechanics of OOP. Inherıtance provides child class type object act like parent class type object by inheritence. Polimorphism provides parent class type object can act like chıid class type object. Internal mechanics are very different.

    • @elizaalwani9200
      @elizaalwani9200 2 роки тому

      So does the reference type or object type determine which method is used

    • @KaraSuraDraw1
      @KaraSuraDraw1 2 роки тому

      @@elizaalwani9200 The object type

    • @brutusjackendy3658
      @brutusjackendy3658 2 роки тому

      @@elizaalwani9200 The object type does.

    • @nolan_villeneuve
      @nolan_villeneuve 2 роки тому +4

      @@elizaalwani9200 the object type does. BUT the availability of methods is determined by the reference type.

  • @feynthefallen
    @feynthefallen 7 місяців тому +3

    It's always nice to see you still got the basics down, even though I think I never EVER went and thought "I'm gonna use polymorphism on that sucker", but just went and did it.

  • @amphousee
    @amphousee 5 місяців тому +11

    2024 and this is still the best short explaination of polymorphism on UA-cam.

  • @1337-p3h
    @1337-p3h 3 роки тому +58

    Very good videos. You explain things in ways that eliminates confusion and covers all bases.

  • @mrtoast244
    @mrtoast244 2 роки тому +21

    John is so concise in his teaching, my lecturer literally takes two hours to cover the exact same concepts

  • @madmalik2776
    @madmalik2776 2 місяці тому +1

    I struggled with understanding polymorphism after reading the entire chapter twice, but I finally grasped the concept after watching this 7-minute video. Thank you so much for the help!

  • @SoundSpaceStation
    @SoundSpaceStation Рік тому +13

    I always wonder why University teachers spend whole semester to explain the topic but you still don't understand, but here on you tube you watch 7 minutes video about the topic and fully understand what the heck it is all about .
    Thank you John very much for your great content!

    • @eric.m5790
      @eric.m5790 Рік тому

      University teachers are not programmers. If you want to learn how to swim i think its best to learn from someone that already knows how to swim

    • @michimarz
      @michimarz Рік тому +5

      John has some very good videos, but this one is kinda disappointing, I'd say. It's not exactly polymorphism what John is explaining here. It's more like he's only describing inheritance. That said, I think you should have listened more carefully to your Professor instead.

    • @JJJJ-gl2uf
      @JJJJ-gl2uf Рік тому +2

      Surely your college teachers aren't spending an entire semester explaining one concept to you. Java [programming] doesn't come easily or quickly to everyone, maybe hit the books a bit harder or do what you're doing here: supplement your college lessons with YT videos.

  • @firasjab
    @firasjab 2 роки тому +11

    I think what you have described here is simply inheritance & method overloading. Polymorphism is a bit more advanced than that. You could for example have declared the cat and dog objects as Animal. That would at least have introduced the concept of polymorphism.

    • @insertname6
      @insertname6 7 днів тому

      What he explained could be called as polymorphism, specifically early-binding or compile-time polymorphism. What you are talking about is late binding or runtime polymorphism. Java can do both. But, yeah he did miss out on the runtime polymorphism.

  • @lisahlee5678
    @lisahlee5678 3 роки тому +24

    You have no idea how I struggled to understand this, about 5 hours before exam i stumbled upon this video, thank you. It was super easy to understand, never thought someone could explain polymorphism this way

  • @darylbaptie5159
    @darylbaptie5159 Рік тому +1

    Thanks John! After hours of trying to find a clear explainaton you wrapped it up in 7 minutes, thanks again!

  • @fallennarcotic6981
    @fallennarcotic6981 2 роки тому +1

    You have not fully understood a problem if you can not explain it to someone else.
    This guy is an expert in his field making the explanation affordless

  • @ainsleys4402
    @ainsleys4402 Рік тому +2

    I don't know how to express my gratitude dude, you've saved me. I've been struggling really hard with my Java class and you have a gift for explaining in a way that scratches my brain the right way.

  • @cristhianjesus8978
    @cristhianjesus8978 9 місяців тому +1

    You are an amazing teacher, know that. I've been doing a lot of java courses and these topics are always convoluted and extremely difficult to understand, but you've managed to explain in a simple way. Thanks!

  • @RJones-mx2oi
    @RJones-mx2oi 2 роки тому +1

    I really wish I had found you and your channel months ago. Even though you are speaking fast, I am grasping and retaining the concept to write into code.
    Thank you so much!!!

  • @rizcmt195
    @rizcmt195 3 роки тому +1

    excellent spent 2 hours watching diff videos to understand the concept but you explained way better and way easy from all of them

  • @vaio007
    @vaio007 2 роки тому +1

    The best Java programming youtuber !! Wish I had known his channel back in 2021 beginning when I started the programming module in Uni.. Explains way better than many of my lecturers ! Thank You !!!

  • @prathapkoththigoda9471
    @prathapkoththigoda9471 3 роки тому +4

    It was a nightmare to find a video to understand Polymorphism. Thanks a lot.

  • @daniaaguila9824
    @daniaaguila9824 2 роки тому +3

    Hi John, thanks for your Java tutorials with non-monotone voice. If you can explain more about composition and aggregation in Java that would be great (your explanations are easier to digest compared to other youtube tutorials)!

  • @howaboutsomesoyfood
    @howaboutsomesoyfood 2 роки тому

    straight to the point way of explaining this concept, most others just over-complicate it and are needlessly verbose.

  • @jimmysmith9462
    @jimmysmith9462 2 роки тому +1

    That was such a simple explanation that was being made WAY too complicated in my class. Thank you for putting this stuff out there.

  • @ironbirdstudios
    @ironbirdstudios 11 місяців тому +2

    i usually never comment on videos, but this guy deserves it all. help me finally end my struggle with CSE 205.

  • @shankar7435
    @shankar7435 Рік тому +2

    I guess what was explained in the video is inheritance. As someone commented " Inherıtance provides child class type object act like parent class type object by inheritance. Polymorphism provides parent class type objects that can act like chıid class type objects. Internal mechanics are very different."

  • @xenophage5562
    @xenophage5562 Рік тому +1

    This was a fantastic explanation that I was able to wrap my head around, bravo good sir!

  • @ChrisLevi22
    @ChrisLevi22 Рік тому

    this guy explained a concept in 7 minutes so much better than my professor could in 2 hours. Unreal man. Such a lifesaver

  • @agreizda4323
    @agreizda4323 5 місяців тому

    I am currently studying for my finals exam in Germany and this is just perfectly explained. THANKS!

  • @crawfishmedia
    @crawfishmedia 2 роки тому

    I'm in a Java course and wasn't understanding this topic. Now its perfectly clear. THANK YOU!

  • @maniac7591
    @maniac7591 2 роки тому +1

    Great explanation. I've been trying to study up for an interview (has been years since I graduated and been in a different field so I forgot everything). When I was studying it wasn't clear that method overriding and method overloading were part of Polymorphism. They made it seem like they were totally different things so thank you for clearing it up!

  • @Molotom
    @Molotom 3 роки тому +3

    Thanks for the video! You're helping a beginner coder in college out quite a bit :)

  • @FifiToJaITylkoJa
    @FifiToJaITylkoJa 2 роки тому +36

    ay yo dont delete comments that actually explains what polymorphism is.

  • @NatanStarke
    @NatanStarke 2 роки тому +1

    Long time im out of programming life but seeing this video kinda make me happy remembering some stuff. Also very good explanations!

  • @vanshika.singh.1
    @vanshika.singh.1 2 роки тому +1

    The fact that this was explained so perfectly and clear and it just clicked so well. Amazing job done!

  • @being_sentient
    @being_sentient Рік тому

    Hi. I am learning Java and I frequently drop here to get things straight. This video does a very good job of introducing polymorphism in a simple manner. But what I would also like to add, is spending some time to explain compile-time and run-time polymorphism. You can do one better by disclosing what polymorphism generally is(that is in the natural world) and how we can try to effect the same phenomenon to objects in Java (since objects in OOP languages mirror real-world objects). There are two ways to imbibe this phenomenon in an object in Java: at compile-time and run-time . The techniques of method overloading and method overriding then happened to be just a natural consequence of acheiving the desired effect. I don't know if I got it backward. I felt the emphasis should be on the phases in the lifecycle of a program.

  • @thezopelo
    @thezopelo 11 місяців тому

    Thank you for the clarification on overloading vs overriding.

  • @thomass1891
    @thomass1891 Рік тому

    I was going to quit my programming course and go back to working at Sonic, but then I came across your video and it just clicked. NO exaggeration, God bless you.

  • @RefaatIbrahimXIT
    @RefaatIbrahimXIT 5 місяців тому +1

    Polymorphism is overrider & overload Parent methods.
    Thank you John

  • @holy8782
    @holy8782 Рік тому

    You've explained what this is and how to do it in half the time and made it 10x more interesting than my instructor. No insult to him. But he just made it sound way more complicated than it actually was.

    • @michimarz
      @michimarz Рік тому +1

      It's because polymorphism is unfortunately more complicated than what he's saying here.

  • @Raccoon_In_A_Suit
    @Raccoon_In_A_Suit 6 місяців тому

    Words fall short to convey how helpful this lecture was sir.Thank you ❤❤

  • @jenniferr2033
    @jenniferr2033 2 роки тому

    Explaining things better than youtubers with 500k+ Subscribers ...John you are doing gods work thank you so much

  • @devangprabhune3591
    @devangprabhune3591 Рік тому +1

    You're way of explaining is playful and very expressive. ❤️ it

  • @TheRebelMerchant
    @TheRebelMerchant 3 роки тому

    excellent video. I am a CIS student this is now starting to all make sense.

  • @eetulaakso5374
    @eetulaakso5374 3 роки тому +2

    Thank you! I'm so happy that I found your video. I definetely watch other content from you, since you explain this topic so clearly. This makes so much more sense even in English compared the videos of my native language in which I just don't understand this subject at all.

  • @novanoskillz4151
    @novanoskillz4151 2 роки тому

    wow, i have asked and "re-asked" my professor to explain this to me. and i just wasnt getting it. ive learned more in the first 3 minutes of your video then what my prof. has been trying to explain to me in 4 weeks. Thanks so much.

  • @lazarus8011
    @lazarus8011 Рік тому +10

    Jonny Sins is the best at teaching programming

  • @roverojermainemariongilr.2856
    @roverojermainemariongilr.2856 3 роки тому +1

    O that's great and I'm learning more on your channel! Thank you for this!
    Love from the Philippines!

  • @smaziano
    @smaziano 8 днів тому

    Just wanted to point that you have a good sense of humor… all this based on the Kramer picture in the back… legendary

  • @carina.zip2002
    @carina.zip2002 2 роки тому

    My comp sci final is in two days and you are the only reason I'm not crying right now.

  • @FazalMalik
    @FazalMalik 2 роки тому

    I just watched your video , I am little bit confused, you made it very easy to learn coding.

  • @tanyashankar1664
    @tanyashankar1664 2 роки тому

    Hi,John...you made my life so easy..was struggling to understand the polymorphism concept until i found your video...much love from india

  • @Alibeee87
    @Alibeee87 2 роки тому

    Thank you for helping me get through my first year as a graduate student!

  • @NYUCODERS
    @NYUCODERS 7 місяців тому +1

    He made it Simple. Thank you 😊

  • @alexeysytnikov6220
    @alexeysytnikov6220 4 місяці тому

    Amazing explanation, John! Can I overload a class constructor?

  • @bemeb41yashsakpal90
    @bemeb41yashsakpal90 Рік тому

    This guy knows the art of teaching, he explained all the concepts in such a smooth way, he makes learning fun & interesting 😇👍

  • @tryfonmichalopoulos5656
    @tryfonmichalopoulos5656 3 роки тому +1

    0:38 - "morphism" actually originates from the greek word "morphi", which directly translates into the english word "form".

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому

      Cool! Got it right and didn't even know it 👍

  • @lootster
    @lootster 4 місяці тому

    I don't understand why nobody can explain Polymorphism in such a simple yet elegant way!

  • @thalibmuhammad9519
    @thalibmuhammad9519 2 роки тому

    i bought your course in thinkific, you are awesome, but the Thinkific platform is streaming is so slow, and the player is buggy and keeps switching the video quality when i switch to full screen

  • @MYTHIICOOL
    @MYTHIICOOL 7 місяців тому

    John you might be one of the best tutors on UA-cam🙏🏼

  • @arno5405
    @arno5405 3 роки тому +3

    Well done my guy. Great video

  • @PremChand-sb3vq
    @PremChand-sb3vq 3 місяці тому

    Wow!!! Extraordinary skills on explaining the concepts🎉

  • @linkedprosperity
    @linkedprosperity 2 роки тому

    So fun with John...geez I have to get his training...makes Java fun.

  • @kibuulekalembe4726
    @kibuulekalembe4726 2 роки тому

    very helpful. Understood polymorphism and encapsulation in less than 30 minutes.

  • @lucifersenpai1948
    @lucifersenpai1948 2 роки тому

    Watching this video i exclaimed three times "Wow! this guy is great". Subscribed.

  • @yaknuelgh
    @yaknuelgh 2 роки тому

    God bless any UA-camr including you John who teaches coding.

  • @stopfbums
    @stopfbums Рік тому

    Wow this is just amazing.
    Currently studying computer science and you help me so much!

  • @waheed-ou4ek
    @waheed-ou4ek 7 місяців тому

    I'm speechless for this great tutorial ever.... Earn my subscription....!!! Very simple to understand....!!!!

  • @increment-
    @increment- 8 місяців тому

    2-3 uni lectures in 7 minutes, ur amazing!

  • @Moch117
    @Moch117 2 роки тому

    Not sure if you'll see this comment but here goes:
    I been watching your video on Polymorphism and Inheritance. I understood everything until now where I saw syntax when declaring a new object such as this:
    Beverage temp = new Coffee(); //Coffee is a subclass. There is an inheritance to this : class Coffee extends Beverage { etc,,}}
    I always thought instead of reading Beverage, this must have the same name as the Constructor i.e it should say Coffee temp = new Coffee().
    Does this work because Coffee is a subclass of Beverage? And with the code above, does this mean temp is now an instance of the Coffee class rather than Beverage class?

    • @CodingWithJohn
      @CodingWithJohn  2 роки тому

      I do read every comment on all my videos (except possibly replies, cause the notifications are weird for those). I don't have the time to reply to all of them, but I do read them.
      In short, you're correct. Coffee is a subclass of Beverage, which is often known as an "is a" relationship. Coffee "is a" Beverage, so Java allows that. You could even have a subclass of Coffee like "ClassicRoast", and you could do:
      Beverage myBev = new ClassicRoast();
      or
      Coffee myCof = new ClassicRoast();
      All ClassicRoasts are Coffees, and all Coffees are Beverages. But not all Beverages are Coffees, and not all Coffees are ClassicRoasts.
      However there are some subtleties about how those objects are treated when you make them like that. One of my recent videos is all about upcasting and downcasting and it talks about this extensively. I think it will answer a lot of your questions:
      ua-cam.com/video/HpuH7n9VOYk/v-deo.html
      Great question, and thanks for watching!

  • @lit_lay
    @lit_lay Рік тому

    I was really confused
    but after watching this, I realized that I have done this in my program already but I don't know it's polymorphism .. thanks

  • @protocolcode2703
    @protocolcode2703 3 роки тому

    Thank you so much. I was looking at a video at linkedin learning an I was about to quit learning java due to that video. You made it so simple and easy. Thank you from the bottom of heart.

  • @textinface1
    @textinface1 Рік тому

    Amazing explanation. I'm sure you already know but your teaching skills are helping thousands of students including myself. Thank you so much!

  • @Htman
    @Htman 11 місяців тому

    Yoo John you are incredibly brilliant at teaching Java.

  • @heartoutloud7498
    @heartoutloud7498 2 роки тому

    Ur explanations are as clean as ur code John. Thank you

  • @alanfang7665
    @alanfang7665 9 місяців тому

    Thank you for explaining the topic so well..... I found your material way easier to digest than my java class! Doing God's work out there.

  • @Lisi_Mxo
    @Lisi_Mxo Рік тому

    I look at topic in text book. I come here, I listen for 7 minutes. I save myself a headache. Come exam time, I just gotta chomp chomp and nom nom my way through that shit. Thank you so much, man.

  • @zero_n_one3782
    @zero_n_one3782 3 роки тому +1

    Thank you for the videos. I have humble request for you to make a clear and understandable videos regarding polymorphism via inheritance and polymorphism via interface and passing an object as argument. Thank you once again for good video.

  • @giaccommander7474
    @giaccommander7474 2 роки тому

    I learned the theory about 5 times but never had to use it because didn´t find a job as juniorDev. but this time I think I got it. THX John.

  • @7002K
    @7002K 3 роки тому

    Awesome now I will never forget about method overriding and overloading

  • @TheRealFenwick
    @TheRealFenwick 3 роки тому +4

    Thank you so much John! you have helped me so much with my internship! Shout-out from Australia

  • @ibrahimaminu4045
    @ibrahimaminu4045 2 роки тому

    Man how did i only find this channel now great content so easy to understand concepts the way you explained in this video!!

  • @youvegotmail9385
    @youvegotmail9385 2 роки тому

    My dude is awesome. Would be awesome to work under someone with his knowledge...and humor.

  • @paulsnehasish5830
    @paulsnehasish5830 2 роки тому

    for beginners: Method Overloading is categorized under Compiletime polymorphism and Method Overriding is categorized under Runtime Polymorphism

  • @kathrinm2420
    @kathrinm2420 10 місяців тому

    You really are a great explainer, thank you! I also didn't get the concetp at uni

  • @pradiptahafid
    @pradiptahafid Рік тому

    a living room and a highly knowledge guy. that's all it takes to teach people around the world

  • @emilyoldson8213
    @emilyoldson8213 2 роки тому

    Just found you today and am so thankful I did! Thank you!!

  • @carlpilongo539
    @carlpilongo539 Рік тому +1

    How is this different from inheritance?
    Im still very confused how to differentiate them

  • @ManishKumar-xw3gs
    @ManishKumar-xw3gs Рік тому

    I have an important question: why do we override methods in java if we can create a new method in sub class with a different name??

  • @surajpatel4073
    @surajpatel4073 Рік тому +1

    Yo, can u make a video on explanation of Method Overriding in JAVA ,would really love to watch your explaination

  • @diodesu
    @diodesu 2 роки тому

    Binge watching this man's videos. He's something else!

  • @Curiousgoogler
    @Curiousgoogler 7 місяців тому

    Thank you sir for making this concept easy to understand.

  • @MyLe-wc5dg
    @MyLe-wc5dg 3 роки тому +1

    Heyy thank you for this video. Your pronunciation as well as explanation are really easy to understand for a Vietnamese student like me. Keep uploading more informative video please 🙏 Have a nice day ☺️☺️

  • @juicifer2024
    @juicifer2024 2 роки тому

    Explaining what my comp sci professors couldn't explain during lectures...I do realize you have the benefit of hindsight and editing to make videos go a lot smoother than lectures, and there absolutely is value to lectures since we can actively ask questions and receive answers...But the way you structure your videos has been all but confusing thus far. Love this page.

  • @cutecatshorts3464
    @cutecatshorts3464 2 роки тому

    man I'd love to watch spring videos you create

  • @midnaite
    @midnaite 3 роки тому +3

    I'm struggling with the instantiation of the subclass. Well, it happens that the way I learned to do my instantiations is as it follows:
    SubClass object = new SubClass();
    But some people do it differently, and that is the way that it is represented in the official Java documentation about Polymorphism:
    SuperClass object = new SubClass();
    And I can't figure out why is this even a possibility, because when you instantiate objects with the second way, you can't access the SubClass methods (unless they are overrided methods and have the same name in both classes).
    Could you explain this to me? Because I noticed that in the video you did the instantiation the same way as I do. Thanks in advance.

    • @CodingWithJohn
      @CodingWithJohn  3 роки тому +5

      Great question! You can certainly do both, and using the superclass as the type has the limitations you noted.
      Most of the time, you're just fine using the SubClass as the type, as you describe how you usually do it. However, there are situations where it makes sense to use the superclass, such as specifically when there is a polymorphic method like you noted.
      Let's say you had an Instrument super class, and a bunch of sub classes of Instrument like Guitar, Trombone, Drum, etc.
      Your Instrument class could have a play() method that makes a sound, and all subclasses would override that method with their own implementation.
      You could write a method that looks like this:
      void playSound (Instrument instrument){
      System.out.println("Playing my sound: " + instrument.play());
      }
      This method doesn't know and doesn't care what type of instrument is passed in - it just needs it to be an Instrument, so that it knows it can call its play() method.
      If you want to use that playSound() method in that kind of situation, you have to create your instrument like:
      Instrument drum = new Drum();
      playSound(drum);
      When working with collections, you'll probably run into similar situations, just with Interfaces instead of superclasses.
      For example, ArrayList is an implementation of the List interface. So usually when declaring an ArrayList, you should do this:
      List names = new ArrayList();
      This list happens to use an ArrayList as its underlying implementation, but any method that takes a List of Strings doesn't care whether you use an ArrayList, or LinkedList, or whatever. Then you can have a method like this:
      void printNames (List nameList) {
      ...
      }
      Similar to the playSound() method above, this method doesn't care whether you used an ArrayList or some other kind of List implementation - it just needs to know it's some kind of List to do what it has to do. And the user of the method can use whatever type of List they want to use for their particular situation.
      That's a very long answer, but hope it helps clarify it a bit!

    • @midnaite
      @midnaite 3 роки тому +1

      @@CodingWithJohn I can't thank you enough for this!!!! It was really helpful. Thank youu

    • @MyLe-wc5dg
      @MyLe-wc5dg 3 роки тому +1

      I am having the same question. Thank you for asking @Jorge and thank @John for the best explanation 😭😭💕

    • @ArskaAdventures
      @ArskaAdventures 2 роки тому

      I just can't believe this. John actually helps people THIS WELL in the comments. I have no words. 👍👍👍

  • @nigelkay6264
    @nigelkay6264 2 роки тому

    i think if you make a 2-3 hour video no one, and I mean no one will ever fail java! ever again Sir John.

  • @R3Z3R3CT10N
    @R3Z3R3CT10N 2 роки тому

    Well, enjoyed all the munchs, chomps, and noms while learing something again in a new way. Was grateful this was in my feed/recommendations.

  • @sujitsharma4792
    @sujitsharma4792 3 роки тому +2

    Very well explained... It will surely lead to Subscription++

  • @atb4352
    @atb4352 Рік тому

    It's crazy that I didn't know what the term polymorphism meant but I knew what is was if that makes sense. Like I understood the concept of overloading and overiding methods in child classes but the name was just daunting.