C# polymorphism 🎭

Ғылым және технология

C# polymorphism tutorial example explained
#C# #polymorphism #tutorial
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!");
}
}
}

Пікірлер: 87

  • @BroCodez
    @BroCodez3 жыл бұрын

    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
    @wiskasIO2 жыл бұрын

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

  • @figgiano1

    @figgiano1

    8 ай бұрын

    😂

  • @videolosss
    @videolosss2 жыл бұрын

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

  • @MrJeeoSoft
    @MrJeeoSoft2 жыл бұрын

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

  • @paleonard1979
    @paleonard19798 ай бұрын

    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!

  • @ilakutemmanuel9688
    @ilakutemmanuel968810 ай бұрын

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

  • @pavidevi86
    @pavidevi862 жыл бұрын

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

  • @jktenny
    @jktenny Жыл бұрын

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

  • @omojolajoshua
    @omojolajoshua Жыл бұрын

    Super awesome explanation. Thank you!!!

  • @vFedora
    @vFedora2 жыл бұрын

    Thank you bro.Your vids are just amazing.

  • @AliHassan-ec9nu
    @AliHassan-ec9nu Жыл бұрын

    Thanks for such a simple and beautiful example

  • @YEAR2001
    @YEAR20012 жыл бұрын

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

  • @CYON4D
    @CYON4D Жыл бұрын

    Very nice and simple explanation of the subject.

  • @alex_opr
    @alex_opr2 ай бұрын

    Very well explained, thank you!

  • @rui9078
    @rui90782 жыл бұрын

    so simple and easy to understand. nice vido bro!

  • @tithiram
    @tithiram2 ай бұрын

    Nice and simple explanation. Thanks a lot :)

  • @masoudrahzani
    @masoudrahzani2 жыл бұрын

    really really great! thanks

  • @H4KnSL4K
    @H4KnSL4KАй бұрын

    Nice and concise!

  • @MethodOverRide
    @MethodOverRide4 ай бұрын

    Fantastic video!

  • @alexanderpopvelichkov8850
    @alexanderpopvelichkov88506 ай бұрын

    very clear explaination!

  • @spartanranger
    @spartanranger2 жыл бұрын

    Thanks for the video Bro.

  • @bartosz8117
    @bartosz8117 Жыл бұрын

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

  • @fnarmusiccomposition3418
    @fnarmusiccomposition34182 жыл бұрын

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

  • @kopilkaiser8991
    @kopilkaiser8991 Жыл бұрын

    You are an Awesome teacher🎉

  • @mone9366
    @mone9366 Жыл бұрын

    Thank you!

  • @nadaelnagar4174
    @nadaelnagar417410 ай бұрын

    Amazing example

  • @cloudguy4192
    @cloudguy4192 Жыл бұрын

    excellent video!!!

  • @davidsantos8249
    @davidsantos82492 жыл бұрын

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

  • @AFaridos
    @AFaridos Жыл бұрын

    Thank you bro!

  • @bokooo3129
    @bokooo31293 ай бұрын

    Thank you elder bro that was very helpfull 😊

  • @ranjanadissanayaka5390
    @ranjanadissanayaka53906 ай бұрын

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

  • @user-pc2vv6ue8v
    @user-pc2vv6ue8v2 ай бұрын

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

  • 3 жыл бұрын

    Thanks Bro!

  • @raheelshayaan
    @raheelshayaan8 ай бұрын

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

  • @stevancosovic4706
    @stevancosovic47063 жыл бұрын

    Thanks:)

  • @ikuubi
    @ikuubi7 ай бұрын

    Brooooooooooooooooo this is so clear!

  • @armanir1571
    @armanir1571 Жыл бұрын

    thanks a lot man

  • @STUPIDYOUTUBE_HIDINGMSGS
    @STUPIDYOUTUBE_HIDINGMSGS2 жыл бұрын

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

  • @najimpinjari6077
    @najimpinjari60777 ай бұрын

    great to have you

  • @ichig085
    @ichig0859 ай бұрын

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

  • @zoop391
    @zoop391 Жыл бұрын

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

  • @alexgolomb363
    @alexgolomb363 Жыл бұрын

    Thanks bro

  • @ahmedel-saadany703
    @ahmedel-saadany703 Жыл бұрын

    🖤🖤

  • @Coder991
    @Coder991 Жыл бұрын

    awesome

  • @FullExtension1
    @FullExtension1 Жыл бұрын

    you are such a bro, bro.

  • @HoNow222
    @HoNow222 Жыл бұрын

    very good video

  • @blizzardengle
    @blizzardengle25 күн бұрын

    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.

  • @gilbertdavid9582
    @gilbertdavid9582 Жыл бұрын

    thanks

  • @dimitryaujour318
    @dimitryaujour318 Жыл бұрын

    your the reallest!

  • @user-so6pp9iq5y
    @user-so6pp9iq5y2 ай бұрын

    nice tutorial

  • @qardin3079
    @qardin30792 жыл бұрын

    so nice

  • @Tymonello
    @Tymonello Жыл бұрын

    thanks bro

  • @alexizz8012
    @alexizz8012 Жыл бұрын

    This guy is saving me so hard

  • @youcan_sprules
    @youcan_sprules Жыл бұрын

    Nicd

  • @najimpinjari6077
    @najimpinjari60777 ай бұрын

    love from india sir

  • @caseyspaulding
    @caseyspaulding Жыл бұрын

    Gold

  • @user-gq4ln6mm9j
    @user-gq4ln6mm9j Жыл бұрын

    nice nice

  • @adamnowicki1425
    @adamnowicki1425 Жыл бұрын

    Boaty McBoat Face thx for video

  • @erenardakaplan7984
    @erenardakaplan79847 ай бұрын

    wow

  • @sekki2554
    @sekki25542 жыл бұрын

    This guy underated af

  • @zdspider6778
    @zdspider6778 Жыл бұрын

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

  • @maxwong1768
    @maxwong1768 Жыл бұрын

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

  • @hsami4208
    @hsami42082 жыл бұрын

    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

    Жыл бұрын

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

  • @samochreno

    @samochreno

    Жыл бұрын

    @@mariapaszkowska3311 i know thats what i said

  • @alikemalulus478
    @alikemalulus4785 ай бұрын

  • @GeneralPet
    @GeneralPet8 ай бұрын

    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?

  • @amanda-we9fv
    @amanda-we9fvАй бұрын

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

  • @justingiovanetti
    @justingiovanetti5 ай бұрын

    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.

  • @michrolaserx10
    @michrolaserx102 жыл бұрын

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

  • @polytrave
    @polytrave7 ай бұрын

    im not a bro but still thanks for the code

  • @MustafaKaradeniz-yy1cx
    @MustafaKaradeniz-yy1cx3 күн бұрын

  • @jaypatel0088
    @jaypatel00886 ай бұрын

    Just Code bro 😉😉😉😎😎😎..

  • @Anthony-op7xz
    @Anthony-op7xz3 жыл бұрын

    Do u have a vid on the virtual keyword

  • @engirckt5410

    @engirckt5410

    3 жыл бұрын

    please make a video on it bro

  • @majeyork

    @majeyork

    2 жыл бұрын

    Thanks bro

  • @sammoc1985
    @sammoc19852 ай бұрын

    Random comment

  • @the_dude_josh
    @the_dude_josh6 ай бұрын

    A random comment down below.

  • @notyou3000
    @notyou30006 ай бұрын

    as

  • @weary867
    @weary8672 ай бұрын

    Random

  • @ancestrall794
    @ancestrall794 Жыл бұрын

    Random comment down below

  • @kvelez
    @kvelez8 ай бұрын

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

  • @felixconrad9248
    @felixconrad92482 жыл бұрын

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

Келесі