C# polymorphism 🎭

  Рет қаралды 76,457

Bro Code

Bro Code

Күн бұрын

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

Пікірлер: 88
@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 9 ай бұрын
😂
@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!
@ilakutemmanuel9688
@ilakutemmanuel9688 11 ай бұрын
The best explanation of polymorphism i have ever come across. Thank you
@paleonard1979
@paleonard1979 9 ай бұрын
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!
@jktenny
@jktenny Жыл бұрын
Thanks a lot for making this video. The way you explain this is awesome
@pavidevi86
@pavidevi86 2 жыл бұрын
omg i am impressed !!!!...can c# be taught so simple....thank you so much
@omojolajoshua
@omojolajoshua Жыл бұрын
Super awesome explanation. Thank you!!!
@vFedora
@vFedora 2 жыл бұрын
Thank you bro.Your vids are just amazing.
@AliHassan-ec9nu
@AliHassan-ec9nu Жыл бұрын
Thanks for such a simple and beautiful example
@CYON4D
@CYON4D Жыл бұрын
Very nice and simple explanation of the subject.
@alex_opr
@alex_opr 3 ай бұрын
Very well explained, thank you!
@tithiram
@tithiram 3 ай бұрын
Nice and simple explanation. Thanks a lot :)
@rui9078
@rui9078 2 жыл бұрын
so simple and easy to understand. nice vido bro!
@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
@H4KnSL4K
@H4KnSL4K Ай бұрын
Nice and concise!
@masoudrahzani
@masoudrahzani 2 жыл бұрын
really really great! thanks
@MethodOverRide
@MethodOverRide 4 ай бұрын
Fantastic video!
@spartanranger
@spartanranger 2 жыл бұрын
Thanks for the video Bro.
@alexanderpopvelichkov8850
@alexanderpopvelichkov8850 6 ай бұрын
very clear explaination!
@ranjanadissanayaka5390
@ranjanadissanayaka5390 6 ай бұрын
hey sir ! thank you so much for making this video. Can you also make videos on encapsulation and abstraction ?
@bokooo3129
@bokooo3129 4 ай бұрын
Thank you elder bro that was very helpfull 😊
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
You are an Awesome teacher🎉
@bartosz8117
@bartosz8117 Жыл бұрын
This is the first time i clicked like, subscribe and notification bell after seeing one video. (half of it) - Bro!
@cloudguy4192
@cloudguy4192 Жыл бұрын
excellent video!!!
@mone9366
@mone9366 Жыл бұрын
Thank you!
@nadaelnagar4174
@nadaelnagar4174 11 ай бұрын
Amazing example
@AFaridos
@AFaridos Жыл бұрын
Thank you bro!
@fnarmusiccomposition3418
@fnarmusiccomposition3418 2 жыл бұрын
bro code and girafe academy is my favriot youtube channel about programming
@STUPIDYOUTUBE_HIDINGMSGS
@STUPIDYOUTUBE_HIDINGMSGS 2 жыл бұрын
Thanks! Explained clearly! But you missed detailing it further into compile-time and run-time polymorphism?
3 жыл бұрын
Thanks Bro!
@user-pc2vv6ue8v
@user-pc2vv6ue8v 3 ай бұрын
just handled an issue in my case with the help of this video, thank you so much "Bro Code"
@stevancosovic4706
@stevancosovic4706 3 жыл бұрын
Thanks:)
@davidsantos8249
@davidsantos8249 2 жыл бұрын
Great video ! thx u save me my module 9/10 of PSI !!!! HUG FROM PORTUGAL SIUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
@raheelshayaan
@raheelshayaan 9 ай бұрын
i have my midterms in an hour and a half. bro just saved my ass. easily the best youtuber to teach programming.
@armanir1571
@armanir1571 Жыл бұрын
thanks a lot man
@blizzardengle
@blizzardengle Ай бұрын
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.
@najimpinjari6077
@najimpinjari6077 8 ай бұрын
great to have you
@HoNow222
@HoNow222 Жыл бұрын
very good video
@Coder991
@Coder991 Жыл бұрын
awesome
@alexgolomb363
@alexgolomb363 Жыл бұрын
Thanks bro
@ikuubi
@ikuubi 8 ай бұрын
Brooooooooooooooooo this is so clear!
@user-so6pp9iq5y
@user-so6pp9iq5y 3 ай бұрын
nice tutorial
@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
@qardin3079
@qardin3079 2 жыл бұрын
so nice
@FullExtension1
@FullExtension1 Жыл бұрын
you are such a bro, bro.
@ahmedel-saadany703
@ahmedel-saadany703 Жыл бұрын
🖤🖤
@gilbertdavid9582
@gilbertdavid9582 Жыл бұрын
thanks
@ichig085
@ichig085 9 ай бұрын
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.
@Tymonello
@Tymonello Жыл бұрын
thanks bro
@najimpinjari6077
@najimpinjari6077 8 ай бұрын
love from india sir
@youcan_sprules
@youcan_sprules Жыл бұрын
Nicd
@user-gq4ln6mm9j
@user-gq4ln6mm9j 2 жыл бұрын
nice nice
@dimitryaujour318
@dimitryaujour318 Жыл бұрын
your the reallest!
@justingiovanetti
@justingiovanetti 6 ай бұрын
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.
@sekki2554
@sekki2554 3 жыл бұрын
This guy underated af
@GeneralPet
@GeneralPet 8 ай бұрын
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?
@adamnowicki1425
@adamnowicki1425 Жыл бұрын
Boaty McBoat Face thx for video
@erenardakaplan7984
@erenardakaplan7984 8 ай бұрын
wow
@alexizz8012
@alexizz8012 Жыл бұрын
This guy is saving me so hard
@michrolaserx10
@michrolaserx10 2 жыл бұрын
bro i want to asked, where is the static and dynamic in this video?
@amanda-we9fv
@amanda-we9fv Ай бұрын
in line 30, why is it virtual and not abstract? especially as it's designed to be overriden
@zdspider6778
@zdspider6778 Жыл бұрын
If you want to inherit from more than one class, you just use the comma "," operator?
@caseyspaulding
@caseyspaulding Жыл бұрын
Gold
@maxwong1768
@maxwong1768 Жыл бұрын
It would be better to mention that method overriding is a run-time polymorphism first .
@samadhimahawela1941
@samadhimahawela1941 6 күн бұрын
Boaty McBoat Face
@alikemalulus478
@alikemalulus478 6 ай бұрын
@polytrave
@polytrave 8 ай бұрын
im not a bro but still thanks for the code
@Anthony-op7xz
@Anthony-op7xz 3 жыл бұрын
Do u have a vid on the virtual keyword
@engirckt5410
@engirckt5410 3 жыл бұрын
please make a video on it bro
@majeyork
@majeyork 2 жыл бұрын
Thanks bro
@MustafaKaradeniz-yy1cx
@MustafaKaradeniz-yy1cx 23 күн бұрын
@jaypatel0088
@jaypatel0088 7 ай бұрын
Just Code bro 😉😉😉😎😎😎..
@kvelez
@kvelez 9 ай бұрын
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."); } } }
@sammoc1985
@sammoc1985 3 ай бұрын
Random comment
@the_dude_josh
@the_dude_josh 7 ай бұрын
A random comment down below.
@weary867
@weary867 3 ай бұрын
Random
@ancestrall794
@ancestrall794 Жыл бұрын
Random comment down below
@notyou3000
@notyou3000 6 ай бұрын
as
@felixconrad9248
@felixconrad9248 2 жыл бұрын
Your Videos are Very Helpfull, you Earned your GigaChad-Code-Logo
C# interfaces 🐟
5:38
Bro Code
Рет қаралды 125 М.
Object Oriented Programming - The Four Pillars of OOP
11:23
Keep On Coding
Рет қаралды 324 М.
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 191 МЛН
Iron Chin ✅ Isaih made this look too easy
00:13
Power Slap
Рет қаралды 36 МЛН
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 66 МЛН
C# enums 🪐
7:07
Bro Code
Рет қаралды 67 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
C# inheritance 👪
4:29
Bro Code
Рет қаралды 54 М.
C# generics ⁉️
5:33
Bro Code
Рет қаралды 71 М.
Java Polymorphism Fully Explained In 7 Minutes
7:16
Coding with John
Рет қаралды 303 М.
Inheritance vs Interfaces in C#: Object Oriented Programming
49:41
IAmTimCorey
Рет қаралды 101 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 921 М.
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 171 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,6 МЛН
Мой новый мега монитор!🤯
1:00
Корнеич
Рет қаралды 126 М.
Rate This Smartphone Cooler Set-up ⭐
0:10
Shakeuptech
Рет қаралды 6 МЛН