Java dynamic polymorphism ✨

preview_player
Показать описание
Java dynamic runtime polymorphism tutorial explained

#java #dynamic #polymorphism #runtime

//*************************************************
public class Main {

public static void main(String[] args) {

//Dynamic Polymorphism

Animal animal;


if(choice==1) {
animal = new Dog();
}
else if(choice==2) {
animal = new Cat();
}
else {
animal = new Animal();
}
}
}
//*************************************************
public class Animal {

public void speak() {
}
}
//*************************************************
public class Dog extends Animal{

@Override
public void speak() {
}
}
//*************************************************
public class Cat extends Animal{

@Override
public void speak() {
}
}
//*************************************************
Рекомендации по теме
Комментарии
Автор

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

BroCodez
Автор

One of the most understandable lessons on YouTube. Thank you Bro!

nikitamarkovski
Автор

Man I just looked at ur sub count and you have Grown!! Great job with the videos!

meltdown
Автор

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

LamNguyen-nmfq
Автор

The example at the end was great. I think i got a good idea of how it works. Thanks a lot ❤

kemann
Автор

Great vid, I like the video game examples, keep them coming!

cdjosh
Автор

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! :-)

TheSoprah
Автор

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.❤

sunshine
Автор

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

dianamilenaarchilacordoba
Автор

i liked that example with pokemon. that's what i like about this channel. examples are given of what certain methods are used for.

omersond
Автор

You explained everything so well !! *subscribed*

MarcusGrey
Автор

Great, man. I like the way the example is given. To the point

yonatan_song
Автор

I watched a lot of YouTube Java tutorials, You are the best, and I hope you can create more practice Task questions and solutions videos

iztillanurulla
Автор

Amazing job...love the way you explain

AHSANALI-evsx
Автор

Congrats, you beat my professors of my old university. My current one got the same zest as you. Good luck w the Algorithm boss

OneGrindyBoi
Автор

Great! You made it very understandable! Good job!

joviksalmeron
Автор

My ged u explain it clearly bro. Thank you

renecabuhan
Автор

Good video.
BTW, can you make a small java game series or if not that then a video of making a cube in Java?

noah
Автор

All these prayers go towards my next job

Simis
Автор

Thank you bro! let's fight the algorithm :D you deserve it

kedea