Java polymorphism 🏁

Поделиться
HTML-код
  • Опубликовано: 21 окт 2024

Комментарии • 179

  • @BroCodez
    @BroCodez  4 года назад +88

    //****************************************
    public class Main {
    public static void main(String[] args) {

    // polymorphism = greek word for poly-"many", morph-"form"
    // The ability of an object to identify as more than one type

    Car car = new Car();
    Bicycle bicycle = new Bicycle();
    Boat boat = new Boat();

    Vehicle[] racers = {car,bicycle,boat};

    for(Vehicle x : racers) {
    x.go();
    }

    }
    }
    //****************************************
    public class Vehicle {
    public void go() {
    // TODO Auto-generated method stub

    }
    }
    //****************************************
    public class Car extends Vehicle{
    @Override
    public void go() {
    System.out.println("*The car begins moving*");
    }
    }
    //****************************************
    public class Bicycle extends Vehicle{
    @Override
    public void go() {
    System.out.println("*The bicycle begins moving*");
    }
    }
    //****************************************
    public class Boat extends Vehicle{
    @Override
    public void go() {
    System.out.println("*The boat begins moving*");
    }
    }
    //****************************************

    • @kaleldarian8406
      @kaleldarian8406 3 года назад

      I know im asking randomly but does any of you know a way to get back into an Instagram account??
      I somehow forgot the login password. I appreciate any tips you can give me

    • @billydominic4312
      @billydominic4312 3 года назад

      @Kalel Darian Instablaster =)

    • @kaleldarian8406
      @kaleldarian8406 3 года назад

      @Billy Dominic i really appreciate your reply. I found the site thru google and Im in the hacking process atm.
      Looks like it's gonna take quite some time so I will reply here later when my account password hopefully is recovered.

    • @kaleldarian8406
      @kaleldarian8406 3 года назад

      @Billy Dominic it worked and I now got access to my account again. Im so happy:D
      Thanks so much you saved my account :D

    • @billydominic4312
      @billydominic4312 3 года назад

      @Kalel Darian Happy to help :D

  • @lequangnghi194
    @lequangnghi194 3 года назад +86

    I had struggled with figuring out what polymorphism is for weeks
    But with just watching this video
    I feel the power in my hands, everything is so clear now
    I extremely respect what you did

    • @anleuc3246
      @anleuc3246 3 года назад +2

      same :v ổng giảng cuốn thật

    • @lequangnghi194
      @lequangnghi194 3 года назад +1

      @@anleuc3246 tưởng có mỗi tôi là người Việt subscribed kênh này :v

    • @vancelery3475
      @vancelery3475 2 года назад

      ui cong dong nguoi viet day roi, chao cac ban, chuc cac ban hoc vui va thanh cong trogn su nghiep

  • @bahaeddinebenabdallah5323
    @bahaeddinebenabdallah5323 2 года назад +16

    The ammount of times this man has saved me this semester is unreal.

  • @abhishekdas2512
    @abhishekdas2512 4 года назад +81

    Better than my teachers ❤️

  • @kevinnguyen1330
    @kevinnguyen1330 3 года назад +7

    Wow, astonished on how well explained that was. Great video.

  • @kapebreak
    @kapebreak Год назад +4

    my classmates and my batchmates kept on asking me how come i already know all the topics our professor taught.. i told them i binged watch youtube tutorial on your channel and ask them favor subscribe , like and comment . so you'll make more videos for us... we learned so much from you more than what is taught in our school we so much appreciate your efforts bro..🥰🥰🥰

  • @khSoraya01
    @khSoraya01 2 года назад +7

    another way is to use instanceof inside the for loop, we each time check :
    if ( x instanceof Car ) x.go();
    if ( x instanceof Bicycle ) x.go();
    if ( x instanceof Boat ) x.go();
    In case someone don't want to redefine the method go in superclass

    • @draffis
      @draffis Год назад

      we call it narrowing down in polymorphism

  • @mrp.m5404
    @mrp.m5404 3 месяца назад

    This is the best video to understand polymorphism. No doubt! Thank you a lot Bro ❤

  • @cdjosh3568
    @cdjosh3568 4 года назад +23

    great video bro! Also in your examples can you include user input, i think its an important skill to memorize

  • @fredericoamigo
    @fredericoamigo Год назад +2

    As always: a brilliant and helpful tutorial vid! I really appreciate you content, it really helps me learn Java!
    Keep up the good work bro!

  • @ra7man7aj61
    @ra7man7aj61 3 года назад +2

    You are the best Bro. I really appreciate what you did. May the God bless you and keep you enjoy with a happy and relax life all the time.

  • @alikkk9169
    @alikkk9169 2 года назад

    Very good video thank you from Kazakhstan

  • @dianamilenaarchilacordoba4632
    @dianamilenaarchilacordoba4632 Месяц назад

    great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much

  • @leonelmessi3010
    @leonelmessi3010 7 месяцев назад

    very good teachin and clear example. Thank you!

  • @fire_krystal
    @fire_krystal Год назад

    You are the best, thank you for helping me through college

  • @bh3302
    @bh3302 2 года назад

    This is my 2# step. Great video bro

  • @hytalefanboi7471
    @hytalefanboi7471 3 года назад +1

    I didn't know u could tell a for loop to go through all entries of an array. That's super useful

    • @mohammeds6314
      @mohammeds6314 3 года назад +3

      Loop Through an Array with For-Each
      There is also a "for-each" loop, which is used exclusively to loop through elements in arrays:
      for (type variable : arrayname) {
      ...
      }
      example:-
      String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
      for (String i : cars) {
      System.out.println(i);
      }
      output:-
      Volvo
      BMW
      Ford
      Mazda

    • @hytalefanboi7471
      @hytalefanboi7471 3 года назад

      @@mohammeds6314 thanks

    • @mohammeds6314
      @mohammeds6314 3 года назад

      @@hytalefanboi7471 most welcome:)

  • @mulumbacephas5036
    @mulumbacephas5036 3 года назад +2

    Great video simple and clear

  • @Curious_Clover
    @Curious_Clover 8 месяцев назад

    Well this was more effective than my W3Schools, school lesson, and ChatGPT combination learning method. Thanks Bro Code!

  • @albertoam2
    @albertoam2 Год назад

    Thanks for this videos, you are the best lecturer bro!

  • @hannanassour2426
    @hannanassour2426 Год назад

    thank you so much, i watched many vids trying to learn this stuff, no one can teach it like you do

  • @longkesh1971
    @longkesh1971 Год назад

    Thank you for making these videos. Great content.

  • @ahmadal-anzi7160
    @ahmadal-anzi7160 2 года назад +1

    Thanks great job keep going

  • @MatejDrbohlav01
    @MatejDrbohlav01 3 года назад +1

    nicely explained, thanks good for repeating :))

  • @fabian2973
    @fabian2973 Год назад

    That was incredible good explained. Thanks!

  • @jQuery22
    @jQuery22 2 года назад

    Powerful,very educ
    ative and easy to understand,thanks bro code

  • @getachewabera3249
    @getachewabera3249 2 года назад

    thanks for your best explanation

  • @pprsstvz
    @pprsstvz Год назад +1

    This helped a lot, thanks!!

  • @FarizDarari
    @FarizDarari Год назад +1

    Awesome explanation as always!

  • @andresroca9736
    @andresroca9736 3 года назад +1

    Nice bro. Right to the point. Gracias.

  • @vancelery3475
    @vancelery3475 2 года назад

    totally amazing tutorial, you got my subscribe after the second video. Thank you so much sir!

  • @eugenezuev7349
    @eugenezuev7349 5 месяцев назад

    concise and precise.Thanks

  • @rob651
    @rob651 2 года назад

    smashed the like button;
    dropped comment;
    subscribed;
    so now I'm fellow bro, bro;

  • @lamias7712
    @lamias7712 2 года назад

    As simple as that . THANKS Bro

  • @eyueldemrew5620
    @eyueldemrew5620 2 года назад +1

    Easy as f**k, thank u Bro.

  • @koja3371
    @koja3371 Год назад

    very helpful, thanks

  • @inazumaeleven9102
    @inazumaeleven9102 3 года назад

    Your explanations are perfect

  • @Simis999
    @Simis999 2 года назад

    I was talked to and learned something new (y)

  • @dllm3tommy741
    @dllm3tommy741 Год назад

    Thanks for your video

  • @majid1885
    @majid1885 3 года назад

    now I'm a hero thanks to you Bro

  • @viktoriyapetrova8692
    @viktoriyapetrova8692 5 месяцев назад

    Bro, you are the best!

  • @supernovic99
    @supernovic99 Год назад +1

    You are the GOAT!!!

  • @charleslyell3748
    @charleslyell3748 3 месяца назад

    Thanks, nice video. In this case the parent class can be modified and x method was included. What if we need to extend somebody's else class? Implement an Interface?

  • @yahyakhawaja88
    @yahyakhawaja88 2 года назад

    Great example

  • @yevgenomelchenko732
    @yevgenomelchenko732 Год назад

    Thanks for the lesson!

  • @Lucyheartfilia-dr7tp
    @Lucyheartfilia-dr7tp Год назад

    this is what ive been looking for thanks bri co

  • @zari_723
    @zari_723 2 года назад

    your vids are great

  • @abdialemu8391
    @abdialemu8391 Год назад

    great job!!!

  • @Ehsanafzali-g9t
    @Ehsanafzali-g9t 5 месяцев назад

    Nice bro keep going you are well🙏

  • @DanSaboia
    @DanSaboia Год назад

    great video !!!

  • @j.m8480
    @j.m8480 2 года назад

    Brilliant tutorial!

  • @derboss66
    @derboss66 2 года назад

    Thank you for everything my bro :D you have helped me so much with your videos :DD!!!!

  • @عبدالرحمنالتميمي-ش8ع
    @عبدالرحمنالتميمي-ش8ع 5 месяцев назад

    Wow!

  • @istiakahmednabil753
    @istiakahmednabil753 7 месяцев назад +1

    Goat of all bro

  • @shko_farhad
    @shko_farhad 8 месяцев назад +1

    good mr bro

  • @jansenzhang7169
    @jansenzhang7169 3 года назад

    very good for me! thank you

  • @EyBossPusi
    @EyBossPusi 6 месяцев назад

    Nice!

  • @JusQuelle
    @JusQuelle 2 года назад

    This was helpful, thank you!

  • @曾毓哲-b1t
    @曾毓哲-b1t Год назад

    Thank you very much!!!

  • @AayushPorwal-g4k
    @AayushPorwal-g4k 10 месяцев назад

    Thanks a lot bro

  • @syed_4138
    @syed_4138 Год назад

    This is kinda similar to array of objects like within a single object we are storing the other objects as well.

  • @cramernord
    @cramernord Год назад

    Great stuff!! 💪

  • @devanthe
    @devanthe 2 года назад

    Gods bless you.

  • @mkkavinda7016
    @mkkavinda7016 Год назад

    youre the best ❤

  • @shanshani6980
    @shanshani6980 Год назад

    Thanks 🎉

  • @tenhociencia9466
    @tenhociencia9466 15 дней назад

    It works even if vehicle is an abstract class?

  • @mahdian11
    @mahdian11 Год назад

    all love your amazing mate

  • @minhtetpaing1695
    @minhtetpaing1695 3 года назад

    Thank you so much sir.

  • @leoniaklebanov2502
    @leoniaklebanov2502 2 года назад

    Awesome

  • @oluwakoredeonasanya3267
    @oluwakoredeonasanya3267 Год назад

    This was a good video

  • @johan-oe9kz
    @johan-oe9kz 2 года назад

    👍

  • @banchitv8466
    @banchitv8466 3 года назад

    You are a god of gods

  • @huuloc8719
    @huuloc8719 3 года назад

    Nice.

  • @ahmadferdaws9761
    @ahmadferdaws9761 6 месяцев назад

    amazing

  • @justinbanza4751
    @justinbanza4751 3 года назад

    Very clear video

  • @vincentpilane4537
    @vincentpilane4537 8 месяцев назад

    Best explanation

  • @joviksalmeron9664
    @joviksalmeron9664 3 года назад

    I like it!

  • @pa-305
    @pa-305 3 года назад

    best brooo

  • @shafikkhan-r4l
    @shafikkhan-r4l 11 месяцев назад

    thanks man. keep up

  • @jkem3311
    @jkem3311 Год назад

    Thanks bro

  • @nafil._
    @nafil._ Год назад

    Thanks🎉

  • @suryaa5564
    @suryaa5564 3 года назад

    Thank You So Much

  • @danny.3036
    @danny.3036 3 года назад

    Thanks, Bro! ☕ You're awesome!

  • @RicardoSouza-sw5un
    @RicardoSouza-sw5un Год назад

    Thanks Bro

  • @dianadoroi154
    @dianadoroi154 3 года назад

    Good job!

  • @joellaprade5332
    @joellaprade5332 Год назад

    Great video

  • @aliozeir4546
    @aliozeir4546 2 года назад +1

    Better than God Viedeo

  • @fitzsimmons7
    @fitzsimmons7 9 месяцев назад

    this was helpful, thx

  • @mohammeds6314
    @mohammeds6314 3 года назад

    super clear thanks

  • @lucnahounou
    @lucnahounou Год назад

    Thanks

  • @kae4334
    @kae4334 6 месяцев назад

    Thank you!

  • @derboss66
    @derboss66 2 года назад

    You are so brosome :)

  • @TheEvertonDias
    @TheEvertonDias Год назад

    Thanks, Bro!

  • @josif3054
    @josif3054 5 месяцев назад

    Appreciate it man!

  • @nghiennghien1808
    @nghiennghien1808 3 года назад

    Thanks so much Bro!!!

  • @uralslife
    @uralslife 8 месяцев назад

    Good job, man!

  • @ilovepizza8263
    @ilovepizza8263 3 месяца назад

    what if one of the 'objects' of the parent class didnt have the go( ) method?

  • @augischadiegils.5109
    @augischadiegils.5109 3 года назад +1

    Thanks bro :)

  • @spooky_zn6
    @spooky_zn6 4 месяца назад

    nice work bro

  • @waligach
    @waligach 8 месяцев назад

    this is the best java oop course