No video

Java dynamic polymorphism ✨

  Рет қаралды 67,775

Bro Code

Bro Code

Күн бұрын

Пікірлер: 126
@BroCodez
@BroCodez 4 жыл бұрын
ALSO KNOWN AS RUNTIME POLYMORPHISM //************************************************* import java.util.Scanner; public class Main { public static void main(String[] args) { //Dynamic Polymorphism Scanner scanner = new Scanner(System.in); Animal animal; System.out.println("What animal do you want?"); System.out.print("(1=dog) or (2=cat): "); int choice = scanner.nextInt(); if(choice==1) { animal = new Dog(); animal.speak(); } else if(choice==2) { animal = new Cat(); animal.speak(); } else { animal = new Animal(); System.out.println("That choice was invalid"); animal.speak(); } } } //************************************************* public class Animal { public void speak() { System.out.println("animal goes *brrrr*"); } } //************************************************* public class Dog extends Animal{ @Override public void speak() { System.out.println("dog goes *bark*"); } } //************************************************* public class Cat extends Animal{ @Override public void speak() { System.out.println("cat goes *meow*"); } } //*************************************************
@noisyguest5249
@noisyguest5249 4 жыл бұрын
Dam u wrote a whole essay of codes in the comment section
@AHSANALI-ev7sx
@AHSANALI-ev7sx 4 жыл бұрын
Got it ...its easy thanks cool that you post code here...bro this an amazing channel...I dint know why its underrated
@BroCodez
@BroCodez 4 жыл бұрын
I cheated. I copied and pasted it from my IDE lol. Don't tell anybody
@noisyguest5249
@noisyguest5249 4 жыл бұрын
@@BroCodez Liar!!!!!!!
@noah77
@noah77 4 жыл бұрын
@@BroCodez it's ok, you still helped
@meltdown6856
@meltdown6856 4 жыл бұрын
Man I just looked at ur sub count and you have Grown!! Great job with the videos!
@BroCodez
@BroCodez 4 жыл бұрын
thanks Melt Down!
@nikitamarkovski7121
@nikitamarkovski7121 2 жыл бұрын
One of the most understandable lessons on KZfaq. Thank you Bro!
@LamNguyen-nm1fq
@LamNguyen-nm1fq 2 жыл бұрын
Love this channel! I spent a whole week trying to understand polymorphism and it was really a nightmare since I couldn't get anything from the lecture at uni. Your video really save my life. Hope that you have patreons so that I could support :3
@kemann3815
@kemann3815 2 жыл бұрын
The example at the end was great. I think i got a good idea of how it works. Thanks a lot ❤
@TheSoprah
@TheSoprah 3 жыл бұрын
I played Pokémon when I was a kid I played WoW when I was a teenager / young adult I study Computer Science as an adult I like this channel! :-)
@sunshine1538
@sunshine1538 2 ай бұрын
Thank you Bro Code. Your video helps me a lot to understand polymorphism! I've spent a few weeks catching those concepts before watching your videos. I should've found this early.❤
@omersond4891
@omersond4891 3 жыл бұрын
i liked that example with pokemon. that's what i like about this channel. examples are given of what certain methods are used for.
@cdjosh3568
@cdjosh3568 3 жыл бұрын
Great vid, I like the video game examples, keep them coming!
@MarcusGrey
@MarcusGrey 3 жыл бұрын
You explained everything so well !! *subscribed*
@noah77
@noah77 4 жыл бұрын
Good video. BTW, can you make a small java game series or if not that then a video of making a cube in Java?
@BroCodez
@BroCodez 4 жыл бұрын
I'm going to be dedicating videos #90-100 in this playlist to games and projects mostly. I believe we are on #86 right now
@noah77
@noah77 4 жыл бұрын
*wow*! Thank you very very much! But only one tutorial of making something 3D?
@BroCodez
@BroCodez 4 жыл бұрын
I actually suck at 3D graphics lol I'll brush up on my skills and see what I can do no promises tho
@noah77
@noah77 4 жыл бұрын
@@BroCodez thanks for your efforts
@yonatan_song
@yonatan_song 3 жыл бұрын
Great, man. I like the way the example is given. To the point
@iztillanurulla151
@iztillanurulla151 8 ай бұрын
I watched a lot of KZfaq Java tutorials, You are the best, and I hope you can create more practice Task questions and solutions videos
@joviksalmeron9664
@joviksalmeron9664 3 жыл бұрын
Great! You made it very understandable! Good job!
@AHSANALI-ev7sx
@AHSANALI-ev7sx 4 жыл бұрын
Amazing job...love the way you explain
@kedea159
@kedea159 3 жыл бұрын
Thank you bro! let's fight the algorithm :D you deserve it
@SereneEverhart
@SereneEverhart 2 жыл бұрын
# 1 best java teacher
@renecabuhan1675
@renecabuhan1675 3 жыл бұрын
My ged u explain it clearly bro. Thank you
@rafikcherfa478
@rafikcherfa478 3 ай бұрын
thank you bro
@ahmadsan2907
@ahmadsan2907 3 жыл бұрын
thank bro you literally saving my A$$ before exam
@alaric-bs3348
@alaric-bs3348 9 ай бұрын
Like and subscribed, thank for saving my assignment grade
@bossowa315
@bossowa315 Жыл бұрын
Yoo Man. Just got the idea from the video. Thanks.🙏
@Wai-uc7tg
@Wai-uc7tg Жыл бұрын
I really like this channel. Thanks Bro Code.
@muhammedenesgokdeniz6201
@muhammedenesgokdeniz6201 2 жыл бұрын
You are awesome man . Thanks a lot
@Dinesh0502
@Dinesh0502 2 жыл бұрын
Nice Example Earned a sub :)
@khaledelsayed3507
@khaledelsayed3507 Жыл бұрын
Thank you for free courses ❤
@Simis999
@Simis999 Жыл бұрын
All these prayers go towards my next job
@noisyguest5249
@noisyguest5249 4 жыл бұрын
I subbed btw
@armandso1
@armandso1 3 жыл бұрын
Hi Bro Code! okay, so I'm totally new to programming and been told to start with Java (something I'm still trying to understand why:)). Anyway, I do like your content but do have a question regarding this particular video. I guess I understand the concept and the logic behind this dynamic polymorphism thing but still having a hard time to understand exactly why and when I would use it. Here's the confusion in my head: Why can't I just use the following if/else statement to achieve the exact same goal: ------------------------------------------------------------------------------------------------------------------ if(choice==1) { Dog dog = new Dog(); dog.speak(); } else if(choice==2) { Cat cat = new Cat(); cat.speak(); } else { Animal animal = new Animal(); System.out.println("That choice was invalid"); animal.speak(); } ------------------------------------------------------------------------------------------------------------------ So, I instantiate a dog object or cat object when and if I need it at runtime just as in the way you have done it. Can you or someone reading this message and who knows the exact answer, please reply to me and let me know because it is driving me nuts trying to figure out. I have been Googling this thing for the past 2 days straight and have not been able to find a detailed explanation as to why someone would do it the Bro way when it can also be done my way. I'm sure there's a very good reason which is why it was implemented in the first place but WHAT IS THAT REASON? :)
@robinshere8697
@robinshere8697 2 жыл бұрын
I think depending on the need ,we can code as per your wish
@elzacontiero2770
@elzacontiero2770 2 жыл бұрын
The whole point of the example is to show how polymorphism works. So, the video shows animal variable being assigned first to a dog, then a cat and a general animal. If you remove the polymorphism by making Dog and Cat not extend Animal your code would compile and work as intended whereas the example in this video would not compile.
@kippenvogelchen9717
@kippenvogelchen9717 3 жыл бұрын
ty! Very good explained! :-)
@danny.3036
@danny.3036 3 жыл бұрын
Thanks, Bro! ☕ You're awesome!
@azizchahbi3538
@azizchahbi3538 Жыл бұрын
Good explanation and examples
@mustafaercan686
@mustafaercan686 6 ай бұрын
Bro explained Factory pattern, without saying it's Factory pattern 👌
@user-zq6yx7of5f
@user-zq6yx7of5f Жыл бұрын
Thank you very much!
@hgatl
@hgatl 3 жыл бұрын
awesome videos for beginners
@vindydog7664
@vindydog7664 2 жыл бұрын
Great youtuber
@minhtetpaing1695
@minhtetpaing1695 3 жыл бұрын
Thank you so much sir.
@TheEvertonDias
@TheEvertonDias Жыл бұрын
Thanks, Bro!
@vpenywise
@vpenywise 2 жыл бұрын
Bros before codes! Good content!
@jamesarden7554
@jamesarden7554 3 жыл бұрын
great video. great teacher
@angelcastineira2561
@angelcastineira2561 4 жыл бұрын
thanks for the video!
@bentameurmohammedayoub1464
@bentameurmohammedayoub1464 2 жыл бұрын
hi Bro why we don't use "Dog dog=new Dog();" and can we use switch statement in a place of "if Statement". thank you bro love the way you explain
@agnivodas
@agnivodas Жыл бұрын
I don't know if this is the correct answer, but here's what I think: if you're working on a very big project, the dog and cat objects will have many methods which are common, like eat(), sleep(), move(), and many more. And if you create more subclasses like Horses and Squirrels and others, their objects will have these methods too. So instead of writing these methods repeatedly in these classes, you could just create them in the Animal class and have these classes inherit the methods from the Animal class. I think that's why we need the Animal class (to keep the methods which are common to all the subclasses) alongside the subclasses (to keep the methods which are more specific to the subclasses). What I mean to say is, if you do Dog dog=new Dog(), you won't inherit the methods from the Animal class, which will force you to write the common methods all over again. But if you do Animal animal=new Dog(), you'll inherit all the common methods from the Animal class, as well as getting the methods specific to the Dog class. And yes, you can use a switch statement instead of an if block.
@eugenezuev7349
@eugenezuev7349 3 ай бұрын
as always, thanks
@thedarkwhisperingcloud
@thedarkwhisperingcloud 8 ай бұрын
Thanks 👍🏾
@noisyguest5249
@noisyguest5249 4 жыл бұрын
Do u think python is better or java
@meltdown6856
@meltdown6856 4 жыл бұрын
If you learn Java, all the other languages seem much much easier. Cuz java is one of the languages with heavier syntax. So id recommend java for beginners. Hope that helped :)
@noisyguest5249
@noisyguest5249 4 жыл бұрын
@@meltdown6856 i started with python
@BroCodez
@BroCodez 4 жыл бұрын
It's personal preference. I learned more about computer science and programming with Java, but Python is more convenient to use since there's less syntax. If you begin with Java and switch to Python later, Python should be very very easy to learn.
@meggieelo
@meggieelo 2 жыл бұрын
YOU ARE THE BEST
@equaliser19
@equaliser19 3 жыл бұрын
Animals go BRUHHH
@akoldousamuel8484
@akoldousamuel8484 2 жыл бұрын
Good
@wallstreetbets7741
@wallstreetbets7741 2 жыл бұрын
Cool I learn it
@camerald8257
@camerald8257 2 жыл бұрын
so amazing 😮
@praisethesun1
@praisethesun1 3 жыл бұрын
wait i have to point something out real quick im pretty sure insted of using if or elseif statements couldnt of u just used a switch statement. great vid btw
@alikkk9169
@alikkk9169 2 жыл бұрын
nice video
@kaushalprasadyadav9242
@kaushalprasadyadav9242 2 жыл бұрын
Please make videos for mobile app development.....
@girl6994
@girl6994 4 жыл бұрын
Good. But we should consider, if a Animal dog is treated as Animal, that is acceptable, but if that dog(which treated as Animal now) is treated as a cat, what exception will we get? I think we will learn that next.
@izaeljunior9007
@izaeljunior9007 2 жыл бұрын
nice video bro
@suryaa5564
@suryaa5564 3 жыл бұрын
Thank You So Much
@mathumathusan154
@mathumathusan154 2 жыл бұрын
aasam vro
@xxg3fallxx589
@xxg3fallxx589 2 ай бұрын
thanks
@rakhalsubbarao8375
@rakhalsubbarao8375 4 ай бұрын
Love u Brother
@mackensonreginaldmichel399
@mackensonreginaldmichel399 Жыл бұрын
Nice content.
@rashmikakelum8803
@rashmikakelum8803 Жыл бұрын
thank you
@danielmilewski7659
@danielmilewski7659 2 жыл бұрын
thanks!
@MrLoser-ks2xn
@MrLoser-ks2xn 2 жыл бұрын
Thanks
@theeverleinhour9616
@theeverleinhour9616 Жыл бұрын
ty bro
@eng6070
@eng6070 2 жыл бұрын
Hey bro, I got a question when watching the video, what's the difference when creating the object using Animal type compared to using the specific type of Dog? Appreciate it if someone could answer this.
@marcosa.6886
@marcosa.6886 2 жыл бұрын
‎La diferencia es que si usas Animal en lugar de Dog el texto que se muestra en la consola será "Animal goes *brrr* en lugar de "Dog goes *bark*!".‎
@augischadiegils.5109
@augischadiegils.5109 3 жыл бұрын
Thankss bro :)
@mariorossi1456
@mariorossi1456 4 жыл бұрын
What will you do after Java?
@BroCodez
@BroCodez 4 жыл бұрын
Python and Javascript for a little while. almost there
@uritaabdelmasih292
@uritaabdelmasih292 Жыл бұрын
Impressive!
@majid1885
@majid1885 2 жыл бұрын
awesome
@ibrahimylmaz8378
@ibrahimylmaz8378 2 жыл бұрын
thanks bro
@baubaudinamo
@baubaudinamo 3 жыл бұрын
Good video.
@nehalayaaz9406
@nehalayaaz9406 4 жыл бұрын
Thanks 🌸
@speklex779
@speklex779 Жыл бұрын
dope video
@pouriahich4215
@pouriahich4215 2 жыл бұрын
🔥🔥🔥
@UltraSolarGod
@UltraSolarGod 2 жыл бұрын
1) Animal animal = new Dog/Cat();??? 2) Animal animal = new animal(); can someone explain this to me how the 1st statement is true as its taking the data type from different class while declaing another class object ?? i know my question make no sense jus try to humor me the only explanation i am think is the animal class is extend to both dog and cat so we can take the data from both the class
@lamias7712
@lamias7712 2 жыл бұрын
and that's that easy :D
@be432n3
@be432n3 2 жыл бұрын
long live bro
@fatihbasal6085
@fatihbasal6085 Жыл бұрын
i am helping you right now
@fatihbasal6085
@fatihbasal6085 Жыл бұрын
becuse im fuckin loved it
@Mohammed-tx1ok
@Mohammed-tx1ok 4 жыл бұрын
what is dynamic polymorphism, is it overiding?
@BroCodez
@BroCodez 4 жыл бұрын
method overriding is an example of dynamic (runtime) polymorphism
@neuzen
@neuzen Жыл бұрын
Why not just create Cat someCat = new Cat() or Dog someDog = new Dog() inside that if-else?
@alexyakoveno4682
@alexyakoveno4682 Жыл бұрын
@chakmak
@chakmak 3 жыл бұрын
where is the new videos?!
@aboyiphilippa1136
@aboyiphilippa1136 4 ай бұрын
@hannibalbianchi1466
@hannibalbianchi1466 3 жыл бұрын
❤❤
@shalajko
@shalajko 3 жыл бұрын
I'm Finding this familiar.
@noisyguest5249
@noisyguest5249 4 жыл бұрын
Am i the only one to still use notepad lmao
@noah77
@noah77 4 жыл бұрын
Download intellij
@BroCodez
@BroCodez 4 жыл бұрын
hey if it works for you, why not
@greeneggsandmushrooms9855
@greeneggsandmushrooms9855 3 жыл бұрын
polywhirl
@kianfrawley8364
@kianfrawley8364 2 жыл бұрын
k
@ashishthakur9983
@ashishthakur9983 Жыл бұрын
111
@maciejkaminski8535
@maciejkaminski8535 3 жыл бұрын
comment
@ordanino9354
@ordanino9354 Жыл бұрын
Bro
@zstar8397
@zstar8397 Жыл бұрын
Yo just wanna say that GOD loved the world so much he sent his only begotten son Jesus to die a brutal death for us so that we can have eternal life and we can all accept this amazing gift this by simply believing in him (Jesus) asking for the forgiveness of your sins and forming a relationship with heavenly father.././...
@kamandshayegan4824
@kamandshayegan4824 2 жыл бұрын
Thanks
@PoorwayTraning
@PoorwayTraning Жыл бұрын
thanks
@romario92730
@romario92730 3 жыл бұрын
Thanks, Bro!
@WajdaanM
@WajdaanM 8 ай бұрын
Free Palestine 🇵🇸
@anjapietralla5767
@anjapietralla5767 7 ай бұрын
@mudassirnaz1813
@mudassirnaz1813 3 жыл бұрын
Thanks
@mudassirnaz1813
@mudassirnaz1813 3 жыл бұрын
thanks
Java exception handling ⚠️
7:53
Bro Code
Рет қаралды 106 М.
Java HashMap 🗺️
13:05
Bro Code
Рет қаралды 81 М.
娜美这是在浪费食物 #路飞#海贼王
00:20
路飞与唐舞桐
Рет қаралды 3,9 МЛН
PEDRO PEDRO INSIDEOUT
00:10
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 18 МЛН
Чёрная ДЫРА 🕳️ | WICSUR #shorts
00:49
Бискас
Рет қаралды 6 МЛН
Learn Any Programming Language In 3 Hours!
22:37
Code With Huw
Рет қаралды 352 М.
Upcasting and Downcasting in Java - Full Tutorial
10:22
Coding with John
Рет қаралды 172 М.
Java enum 🪐
10:50
Bro Code
Рет қаралды 64 М.
Java Polymorphism Fully Explained In 7 Minutes
7:16
Coding with John
Рет қаралды 307 М.
Java static keyword ⚡
8:18
Bro Code
Рет қаралды 111 М.
Java multithreading 🧶
15:18
Bro Code
Рет қаралды 126 М.
Simple Explanation of Polymorphism and Dynamic Binding
3:49
Brandan Jones
Рет қаралды 1,8 М.
娜美这是在浪费食物 #路飞#海贼王
00:20
路飞与唐舞桐
Рет қаралды 3,9 МЛН