Java polymorphism 🏁

Поділитися
Вставка
  • Опубліковано 27 вер 2024
  • Java polymorphism tutorial example explained
    #Java #polymorphism #tutorial #example #explained

КОМЕНТАРІ • 178

  • @BroCodez
    @BroCodez  4 роки тому +87

    //****************************************
    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 2 роки тому +83

    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 2 роки тому +2

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

    • @lequangnghi194
      @lequangnghi194 2 роки тому +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

  • @abhishekdas2512
    @abhishekdas2512 4 роки тому +78

    Better than my teachers ❤️

  • @khSoraya01
    @khSoraya01 2 роки тому +6

    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

  • @cdjosh3568
    @cdjosh3568 4 роки тому +23

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

  • @dianamilenaarchilacordoba4632
    @dianamilenaarchilacordoba4632 17 днів тому

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

  • @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!

  • @mrp.m5404
    @mrp.m5404 2 місяці тому

    This is the best video to understand polymorphism. No doubt! Thank you a lot 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.

  • @shko_farhad
    @shko_farhad 8 місяців тому +1

    good mr 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:)

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

    Awesome explanation as always!

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

    Better than God Viedeo

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

    Easy as f**k, thank u Bro.

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

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

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

    Nice!

  • @spooky_zn6
    @spooky_zn6 3 місяці тому

    nice work bro

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

    very good teachin and clear example. Thank you!

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

    amazing

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

    This was a good video

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

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

  • @عبدالرحمنالتميمي-ش8ع
    @عبدالرحمنالتميمي-ش8ع 4 місяці тому

    Wow!

  • @charleslyell3748
    @charleslyell3748 2 місяці тому

    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?

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

    Nice.

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

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

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

    This is my 2# step. Great video bro

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

    Bro, you are the best!

  • @istiakahmednabil753
    @istiakahmednabil753 6 місяців тому +1

    Goat of all bro

  • @AayushPorwal-g4k
    @AayushPorwal-g4k 9 місяців тому

    Thanks a lot bro

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

    Nice bro

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

    Good bro

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

    all love your amazing mate

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

    Thanks 🎉

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

    Gods bless you.

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

    Thanks bro

  • @RicardoSouza-sw5un
    @RicardoSouza-sw5un Рік тому

    Thanks Bro

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

    Nice

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

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

  • @shafikkhan-r4l
    @shafikkhan-r4l 10 місяців тому

    thanks man. keep up

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

    You are a god of gods

  • @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.

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

    your vids are great

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

    Good job, man!

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

    Good

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

    This helped a lot, thanks!!

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

    I was talked to and learned something new (y)

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

    Thanks

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

    thanks for your best explanation

  • @曾毓哲-b1t
    @曾毓哲-b1t Рік тому

    Thank you very much!!!

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

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

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

    Great example

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

    Thanks, Bro!

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

    very helpful, thanks

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

    Thank you!

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

    You are so brosome :)

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

    this was helpful, thx

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

    Your explanations are perfect

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

    Great video

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

    great video !!!

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

    now I'm a hero thanks to you Bro

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

    Appreciate it man!

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

    tx bro

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

    Great stuff!! 💪

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

    Very clear video

  • @johan-oe9kz
    @johan-oe9kz 2 роки тому

    👍

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

    Thanks for the lesson!

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

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

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

    As simple as that . THANKS Bro

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

    Awesome

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

    youre the best ❤

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

    I like it!

  • @pa-305
    @pa-305 3 роки тому

    best brooo

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

    this is the best java oop course

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

    Good job!

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

    very good for me! thank you

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

    thx bro!

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

    Thank you so much sir.

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

    This was helpful, thank you!

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

    Thank You So Much

  • @GOODBOY-vt1cf
    @GOODBOY-vt1cf 3 роки тому +1

    0:29

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

    What's the difference between abstract and interference

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

    sagol

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

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

    thank you !

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

    How to using polymorphisme in java GUI ?

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

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

    thanks babes

  • @augischadiegils.5109
    @augischadiegils.5109 3 роки тому

    Thankss :)

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

    4:50

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

    comment

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

    Just a comment down below

  • @Katie-zk4xs
    @Katie-zk4xs 2 роки тому

    You should teach college classes!

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

    I just don't understand how you can call other classes from the Main. You're not even including the package. Please help me understand this magic!

    • @charleslyell3748
      @charleslyell3748 2 місяці тому

      Just use "IntelliJ" (simpler) or "Android Studio" (more complex) and things become clear.

  • @someone-ec6pf
    @someone-ec6pf 7 місяців тому

    Does any one knows how to save the polymorphism code in java?

    • @charleslyell3748
      @charleslyell3748 2 місяці тому

      What do you mean by "save the polymorphism code" ?

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

    I didn't understand that for loop😭

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

      It’s a for-each loop. It’s a variant of the for loop (kind of like the do loop is a variant of the while loop.) This same youtube goes over the concept in one of the videos in his 100 Java playlist. It’s probably the best (yet most underrated) explanation out there. Here’s a link:
      ua-cam.com/video/_IT8F5W0ZO4/v-deo.html

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

    bro

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

    plz

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

    bahabikkkkkkkkkkkkkkk

  • @bahaeddinebenabdallah5323
    @bahaeddinebenabdallah5323 2 роки тому +16

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

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

    Thanks