C# polymorphism 🎭

  Рет қаралды 72,261

Bro Code

Bro Code

2 жыл бұрын

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

Пікірлер: 85
@BroCodez
@BroCodez 3 жыл бұрын
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 жыл бұрын
THANK YOU! Your video helped me understand more the concept better than my University teacher and three different books.
@figgiano1
@figgiano1 7 ай бұрын
😂
@videolosss
@videolosss 2 жыл бұрын
Again! Describing difficult concepts so simply. You got the gift
@MrJeeoSoft
@MrJeeoSoft 2 жыл бұрын
Excellent example as well as simple, thank you for sharing!
@paleonard1979
@paleonard1979 7 ай бұрын
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
@ilakutemmanuel9688 9 ай бұрын
The best explanation of polymorphism i have ever come across. Thank you
@pavidevi86
@pavidevi86 2 жыл бұрын
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!!!
@AliHassan-ec9nu
@AliHassan-ec9nu Жыл бұрын
Thanks for such a simple and beautiful example
@vFedora
@vFedora 2 жыл бұрын
Thank you bro.Your vids are just amazing.
@CYON4D
@CYON4D Жыл бұрын
Very nice and simple explanation of the subject.
@alex_opr
@alex_opr Ай бұрын
Very well explained, thank you!
@tithiram
@tithiram Ай бұрын
Nice and simple explanation. Thanks a lot :)
@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
@fnarmusiccomposition3418
@fnarmusiccomposition3418 2 жыл бұрын
bro code and girafe academy is my favriot youtube channel about programming
@rui9078
@rui9078 2 жыл бұрын
so simple and easy to understand. nice vido bro!
@ranjanadissanayaka5390
@ranjanadissanayaka5390 5 ай бұрын
hey sir ! thank you so much for making this video. Can you also make videos on encapsulation and abstraction ?
@alexanderpopvelichkov8850
@alexanderpopvelichkov8850 5 ай бұрын
very clear explaination!
@MethodOverRide
@MethodOverRide 3 ай бұрын
Fantastic video!
@H4KnSL4K
@H4KnSL4K 2 күн бұрын
Nice and concise!
@bokooo3129
@bokooo3129 2 ай бұрын
Thank you elder bro that was very helpfull 😊
@masoudrahzani
@masoudrahzani 2 жыл бұрын
really really great! thanks
@bartosz8117
@bartosz8117 Жыл бұрын
This is the first time i clicked like, subscribe and notification bell after seeing one video. (half of it) - Bro!
@raheelshayaan
@raheelshayaan 7 ай бұрын
i have my midterms in an hour and a half. bro just saved my ass. easily the best youtuber to teach programming.
@higherpurpose1212
@higherpurpose1212 2 жыл бұрын
Thanks! Explained clearly! But you missed detailing it further into compile-time and run-time polymorphism?
@ichig085
@ichig085 8 ай бұрын
This is an example of run-time polymorphism. There's also compile-time polymorphism such as method overloading.
@spartanranger
@spartanranger 2 жыл бұрын
Thanks for the video Bro.
@user-pc2vv6ue8v
@user-pc2vv6ue8v Ай бұрын
just handled an issue in my case with the help of this video, thank you so much "Bro Code"
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
You are an Awesome teacher🎉
@mone9366
@mone9366 Жыл бұрын
Thank you!
@nadaelnagar4174
@nadaelnagar4174 9 ай бұрын
Amazing example
@AFaridos
@AFaridos Жыл бұрын
Thank you bro!
@cloudguy4192
@cloudguy4192 Жыл бұрын
excellent video!!!
@davidsantos8249
@davidsantos8249 2 жыл бұрын
Great video ! thx u save me my module 9/10 of PSI !!!! HUG FROM PORTUGAL SIUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
2 жыл бұрын
Thanks Bro!
@stevancosovic4706
@stevancosovic4706 2 жыл бұрын
Thanks:)
@armanir1571
@armanir1571 Жыл бұрын
thanks a lot man
@zoop391
@zoop391 Жыл бұрын
Ah this explains why my teacher was able to hold various of values of different datatypes using the 'object' datatype as reference.
@najimpinjari6077
@najimpinjari6077 6 ай бұрын
great to have you
@alexgolomb363
@alexgolomb363 Жыл бұрын
Thanks bro
@ikuubi
@ikuubi 6 ай бұрын
Brooooooooooooooooo this is so clear!
@Coder991
@Coder991 Жыл бұрын
awesome
@HoNow222
@HoNow222 Жыл бұрын
very good video
@FullExtension1
@FullExtension1 Жыл бұрын
you are such a bro, bro.
@gilbertdavid9582
@gilbertdavid9582 Жыл бұрын
thanks
@ahmedel-saadany703
@ahmedel-saadany703 Жыл бұрын
🖤🖤
@hsami4208
@hsami4208 2 жыл бұрын
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
@user-so6pp9iq5y
@user-so6pp9iq5y Ай бұрын
nice tutorial
@Tymonello
@Tymonello Жыл бұрын
thanks bro
@youcan_sprules
@youcan_sprules Жыл бұрын
Nicd
@qardin3079
@qardin3079 2 жыл бұрын
so nice
@dimitryaujour318
@dimitryaujour318 Жыл бұрын
your the reallest!
@najimpinjari6077
@najimpinjari6077 6 ай бұрын
love from india sir
@GeneralPet
@GeneralPet 7 ай бұрын
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?
@alexizz8012
@alexizz8012 Жыл бұрын
This guy is saving me so hard
@user-gq4ln6mm9j
@user-gq4ln6mm9j Жыл бұрын
nice nice
@justingiovanetti
@justingiovanetti 4 ай бұрын
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.
@zdspider6778
@zdspider6778 Жыл бұрын
If you want to inherit from more than one class, you just use the comma "," operator?
@adamnowicki1425
@adamnowicki1425 Жыл бұрын
Boaty McBoat Face thx for video
@sekki2554
@sekki2554 2 жыл бұрын
This guy underated af
@amanda-we9fv
@amanda-we9fv 7 күн бұрын
in line 30, why is it virtual and not abstract? especially as it's designed to be overriden
@maxwong1768
@maxwong1768 Жыл бұрын
It would be better to mention that method overriding is a run-time polymorphism first .
@erenardakaplan7984
@erenardakaplan7984 6 ай бұрын
wow
@caseyspaulding
@caseyspaulding Жыл бұрын
Gold
@michrolaserx10
@michrolaserx10 Жыл бұрын
bro i want to asked, where is the static and dynamic in this video?
@alikemalulus478
@alikemalulus478 4 ай бұрын
@polytrave
@polytrave 6 ай бұрын
im not a bro but still thanks for the code
@jaypatel0088
@jaypatel0088 5 ай бұрын
Just Code bro 😉😉😉😎😎😎..
@Anthony-op7xz
@Anthony-op7xz 2 жыл бұрын
Do u have a vid on the virtual keyword
@engirckt5410
@engirckt5410 2 жыл бұрын
please make a video on it bro
@majeyork
@majeyork 2 жыл бұрын
Thanks bro
@the_dude_josh
@the_dude_josh 5 ай бұрын
A random comment down below.
@notyou3000
@notyou3000 5 ай бұрын
as
@sammoc1985
@sammoc1985 Ай бұрын
Random comment
@kvelez
@kvelez 7 ай бұрын
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."); } } }
@ancestrall794
@ancestrall794 Жыл бұрын
Random comment down below
@weary867
@weary867 Ай бұрын
Random
@felixconrad9248
@felixconrad9248 2 жыл бұрын
Your Videos are Very Helpfull, you Earned your GigaChad-Code-Logo
C# interfaces 🐟
5:38
Bro Code
Рет қаралды 118 М.
C# method overriding 🙅
4:02
Bro Code
Рет қаралды 40 М.
Купили айфон для собачки #shorts #iribaby
00:31
The delivery rescued them
00:52
Mamasoboliha
Рет қаралды 10 МЛН
C# getters & setters 🔒
4:06
Bro Code
Рет қаралды 138 М.
Polymorphism in C# |C# Basics for Beginners in Hindi
14:14
Sunny Gamedev
Рет қаралды 92 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
C# static 🚫
5:03
Bro Code
Рет қаралды 63 М.
C# objects 🧍‍♂️
5:01
Bro Code
Рет қаралды 40 М.
C# Polymorphism in 5 minutes!
5:08
Computerix
Рет қаралды 2,4 М.
C# multithreading 🧶
6:59
Bro Code
Рет қаралды 143 М.
4.7: Introduction to Polymorphism - The Nature of Code
8:46
The Coding Train
Рет қаралды 180 М.
What is Polymorphism and what are its types ?
0:56
Interview Happy
Рет қаралды 84 М.
cool watercooled mobile phone radiator #tech #cooler #ytfeed
0:14
Stark Edition
Рет қаралды 9 МЛН
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 9 МЛН
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 1 МЛН
Apple watch hidden camera
0:34
_vector_
Рет қаралды 60 МЛН
Купил этот ваш VR.
37:21
Ремонтяш
Рет қаралды 100 М.