C# polymorphism 🎭

Поділитися
Вставка
  • Опубліковано 21 гру 2024

КОМЕНТАРІ • 96

  • @BroCodez
    @BroCodez  3 роки тому +42

    using System;
    namespace MyFirstProgram
    {
    class Program
    {
    static void Main(string[] args) {
    // polymorphism = Greek word that means to "have many forms"
    // Objects can be identified by more than one type
    // Ex. A Dog is also: Canine, Animal, Organism
    Car car = new Car();
    Bicycle bicycle = new Bicycle();
    Boat boat = new Boat();
    Vehicle[] vehicles = {car, bicycle, boat};
    foreach (Vehicle vehicle in vehicles)
    {
    vehicle.Go();
    }

    Console.ReadKey();
    }
    }
    class Vehicle
    {
    public virtual void Go()
    {
    }
    }
    class Car: Vehicle
    {
    public override void Go()
    {
    Console.WriteLine("The car is moving!");
    }
    }
    class Bicycle : Vehicle
    {
    public override void Go()
    {
    Console.WriteLine("The bicycle is moving!");
    }
    }
    class Boat : Vehicle
    {
    public override void Go()
    {
    Console.WriteLine("The boat is moving!");
    }
    }
    }

  • @wiskasIO
    @wiskasIO 2 роки тому +67

    THANK YOU! Your video helped me understand more the concept better than my University teacher and three different books.

  • @DamnTimCan
    @DamnTimCan 2 роки тому +17

    Again! Describing difficult concepts so simply. You got the gift

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

    The best explanation of polymorphism i have ever come across. Thank you

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

    Legend!! I've been reading a book for ages trying to understand this. Thank you for making such a simple explanation that even my brain can understand!

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

    This is an example of run-time polymorphism. There's also compile-time polymorphism such as method overloading.

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

    omg i am impressed !!!!...can c# be taught so simple....thank you so much

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

    bro code and girafe academy is my favriot youtube channel about programming

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

    Great video ! thx u save me my module 9/10 of PSI !!!! HUG FROM PORTUGAL SIUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

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

    This is the first time i clicked like, subscribe and notification bell after seeing one video. (half of it) - Bro!

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

    Excellent example as well as simple, thank you for sharing!

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

    Very nice and simple explanation of the subject.

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

    i have my midterms in an hour and a half. bro just saved my ass. easily the best youtuber to teach programming.

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

    Very informative, thank you.

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

    Legit the best explanation

  • @Jimbodani
    @Jimbodani 18 днів тому

    your the best mate, you will save with this video on my test

  • @sekki2554
    @sekki2554 3 роки тому +6

    This guy underated af

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

    Super awesome explanation. Thank you!!!

  • @ranjanadissanayaka5390
    @ranjanadissanayaka5390 11 місяців тому +1

    hey sir ! thank you so much for making this video. Can you also make videos on encapsulation and abstraction ?

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

    i love you, my add wont allow me to watch the long tutorials otehr channels post but these are literally saving meeeeeeeeeeeeeee

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

    Nice and simple explanation. Thanks a lot :)

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

    Great tutorial! You should use abstract instead of virtual for the Go method in this case though. This would also mean the class Vehicle has to be abstract as well.

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

      That's right to force each method to Implement go you should make vehicle as abstract cos using normal class with virtual it will be an option to be implemented in child classes, but go must be an abstract for each class inherit vehicle to be force to implement it.

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

    Thanks a lot for making this video. The way you explain this is awesome

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

    Fantastic video!

  • @AliHassan-ec9nu
    @AliHassan-ec9nu Рік тому

    Thanks for such a simple and beautiful example

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

    just handled an issue in my case with the help of this video, thank you so much "Bro Code"

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

    Amazing example

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

    very clear explaination!

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

    Very well explained, thank you!

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

    Thank you bro.Your vids are just amazing.

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

    so simple and easy to understand. nice vido bro!

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

    You are an Awesome teacher🎉

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

    Nice and concise!

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

    great to have you

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

    very good video

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

    Great Bro!

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

    Thank you elder bro that was very helpfull 😊

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

    you are such a bro, bro.

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

    Brooooooooooooooooo this is so clear!

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

    excellent video!!!

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

    awesome

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

    Ah this explains why my teacher was able to hold various of values of different datatypes using the 'object' datatype as reference.

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

    really really great! thanks

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

    Thank you bro!

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

    Thanks for the video Bro.

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

    Thankyou for this, correct me if I’m wrong but can you also have vehicle as as abstract class and have a abstract method with no body which can then be overridden by the other classes ?

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

      yes you are correct but then you HAVE to override it not only can

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

      @@samochreno dont you have to override here too

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

      @@marcusaurelius3487 i dont understand

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

      @@samochreno virtual method can but doesnt have to be overridden, but if the method is abstract you have to override it

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

      @@mariapaszkowska3311 i know thats what i said

  • @AntwiGodwill-o8y
    @AntwiGodwill-o8y 7 місяців тому

    nice tutorial

  • @samizzle.mynizzle
    @samizzle.mynizzle 4 місяці тому +1

    Boaty McBoat Face

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

    My instincts when hearing “polymorphism” is to think cat changes into dog. Car changes to boat. Not cat is also an animal, or car is also a vehicle.

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

    Thank you!

  • @amanda-we9fv
    @amanda-we9fv 6 місяців тому

    in line 30, why is it virtual and not abstract? especially as it's designed to be overriden

  • @user-gq4ln6mm9j
    @user-gq4ln6mm9j 2 роки тому +1

    nice nice

  • @Pocket-domain
    @Pocket-domain Рік тому

    your the reallest!

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

    too good :)

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

    love from india sir

  • @ahmedel-saadany703
    @ahmedel-saadany703 2 роки тому

    🖤🖤

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

    This guy is saving me so hard

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

    Ok but how does it actually work? If it’s like casting where each object is cast to their base class then wouldn’t they lose all their properties that were defined in the child class but not the base?

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

    Thanks! Explained clearly! But you missed detailing it further into compile-time and run-time polymorphism?

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

    It would be better to mention that method overriding is a run-time polymorphism first .

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

    thanks a lot man

  • @ag4-z4z
    @ag4-z4z Рік тому

    Thanks bro

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

    If you want to inherit from more than one class, you just use the comma "," operator?

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

    Nicd

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

    so nice

  • @jaypatel0088
    @jaypatel0088 11 місяців тому +1

    Just Code bro 😉😉😉😎😎😎..

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

    Thanks:)

  •  3 роки тому

    Thanks Bro!

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

    thanks bro

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

    Boaty McBoat Face
    thx for video

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

    bro i want to asked, where is the static and dynamic in this video?

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

    thanks

  • @Anthony-op7xz
    @Anthony-op7xz 3 роки тому

    Do u have a vid on the virtual keyword

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

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ConsoleApp1
    {
    internal class Program
    {
    static void Main(string[] args)
    {
    Car car = new Car();
    Truck truck = new Truck();
    Vehicle[] vehicles = {car, truck};
    List transportation = new List();
    transportation.Add(car);
    transportation.Add(truck);
    foreach (var transport in transportation)
    {
    transport.Go();
    }
    foreach (var vehicle in vehicles)
    {
    vehicle.Go();
    }
    }
    }
    abstract class Vehicle
    {
    abstract public int Speed { get; set; }
    abstract public int Wheels { get; set; }
    abstract public void Go();
    }
    class Car : Vehicle
    {
    public override int Speed { get; set; }
    public override int Wheels { get; set;}
    public override void Go()
    {
    Console.WriteLine("Car is Moving...");
    }
    }
    class Truck : Car
    {
    public override void Go()
    {
    Console.WriteLine("Truck is motion.");
    }
    }
    }

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

    wow

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

    Gold

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

    im not a bro but still thanks for the code

  • @KarasuOfficial-g9v
    @KarasuOfficial-g9v 5 місяців тому

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

    lulu be like

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

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

    A random comment down below.

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

    Your Videos are Very Helpfull, you Earned your GigaChad-Code-Logo

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

    Random comment

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

    as

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

    random comment

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

    Random

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

    Random comment down below