Тёмный

C# polymorphism 🎭 

Bro Code
Подписаться 2 млн
Просмотров 76 тыс.
50% 1

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

Наука

Опубликовано:

 

2 июл 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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
@paleonard1979
@paleonard1979 8 месяцев назад
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 10 месяцев назад
The best explanation of polymorphism i have ever come across. Thank you
@MrJeeoSoft
@MrJeeoSoft 2 года назад
Excellent example as well as simple, thank you for sharing!
@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.
@tithiram
@tithiram 3 месяца назад
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
@alex_opr
@alex_opr 3 месяца назад
Very well explained, thank you!
@rui9078
@rui9078 2 года назад
so simple and easy to understand. nice vido bro!
@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.
@fnarmusiccomposition3418
@fnarmusiccomposition3418 2 года назад
bro code and girafe academy is my favriot youtube channel about programming
@MethodOverRide
@MethodOverRide 4 месяца назад
Fantastic video!
@H4KnSL4K
@H4KnSL4K Месяц назад
Nice and concise!
@bartosz8117
@bartosz8117 Год назад
This is the first time i clicked like, subscribe and notification bell after seeing one video. (half of it) - Bro!
@bokooo3129
@bokooo3129 3 месяца назад
Thank you elder bro that was very helpfull 😊
@user-pc2vv6ue8v
@user-pc2vv6ue8v 3 месяца назад
just handled an issue in my case with the help of this video, thank you so much "Bro Code"
@ranjanadissanayaka5390
@ranjanadissanayaka5390 6 месяцев назад
hey sir ! thank you so much for making this video. Can you also make videos on encapsulation and abstraction ?
@alexanderpopvelichkov8850
@alexanderpopvelichkov8850 6 месяцев назад
very clear explaination!
@masoudrahzani
@masoudrahzani 2 года назад
really really great! thanks
@spartanranger
@spartanranger 2 года назад
Thanks for the video Bro.
@davidsantos8249
@davidsantos8249 2 года назад
Great video ! thx u save me my module 9/10 of PSI !!!! HUG FROM PORTUGAL SIUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
@kopilkaiser8991
@kopilkaiser8991 Год назад
You are an Awesome teacher🎉
@ichig085
@ichig085 9 месяцев назад
This is an example of run-time polymorphism. There's also compile-time polymorphism such as method overloading.
@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.
@STUPIDYOUTUBE_HIDINGMSGS
@STUPIDYOUTUBE_HIDINGMSGS 2 года назад
Thanks! Explained clearly! But you missed detailing it further into compile-time and run-time polymorphism?
@nadaelnagar4174
@nadaelnagar4174 11 месяцев назад
Amazing example
@mone9366
@mone9366 Год назад
Thank you!
@AFaridos
@AFaridos Год назад
Thank you bro!
@ikuubi
@ikuubi 8 месяцев назад
Brooooooooooooooooo this is so clear!
@cloudguy4192
@cloudguy4192 Год назад
excellent video!!!
@zoop391
@zoop391 Год назад
Ah this explains why my teacher was able to hold various of values of different datatypes using the 'object' datatype as reference.
@FullExtension1
@FullExtension1 Год назад
you are such a bro, bro.
3 года назад
Thanks Bro!
@stevancosovic4706
@stevancosovic4706 3 года назад
Thanks:)
@alexgolomb363
@alexgolomb363 Год назад
Thanks bro
@najimpinjari6077
@najimpinjari6077 8 месяцев назад
great to have you
@armanir1571
@armanir1571 Год назад
thanks a lot man
@Coder991
@Coder991 Год назад
awesome
@user-so6pp9iq5y
@user-so6pp9iq5y 2 месяца назад
nice tutorial
@ahmedel-saadany703
@ahmedel-saadany703 Год назад
🖤🖤
@HoNow222
@HoNow222 Год назад
very good video
@dimitryaujour318
@dimitryaujour318 Год назад
your the reallest!
@alexizz8012
@alexizz8012 Год назад
This guy is saving me so hard
@gilbertdavid9582
@gilbertdavid9582 Год назад
thanks
@qardin3079
@qardin3079 2 года назад
so nice
@sekki2554
@sekki2554 3 года назад
This guy underated af
@user-gq4ln6mm9j
@user-gq4ln6mm9j Год назад
nice nice
@Tymonello
@Tymonello Год назад
thanks bro
@najimpinjari6077
@najimpinjari6077 8 месяцев назад
love from india sir
@youcan_sprules
@youcan_sprules Год назад
Nicd
@adamnowicki1425
@adamnowicki1425 Год назад
Boaty McBoat Face thx for video
@maxwong1768
@maxwong1768 Год назад
It would be better to mention that method overriding is a run-time polymorphism first .
@caseyspaulding
@caseyspaulding Год назад
Gold
@zdspider6778
@zdspider6778 Год назад
If you want to inherit from more than one class, you just use the comma "," operator?
@erenardakaplan7984
@erenardakaplan7984 8 месяцев назад
wow
@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?
@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.
@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
@amanda-we9fv
@amanda-we9fv Месяц назад
in line 30, why is it virtual and not abstract? especially as it's designed to be overriden
@michrolaserx10
@michrolaserx10 2 года назад
bro i want to asked, where is the static and dynamic in this video?
@samadhimahawela1941
@samadhimahawela1941 2 дня назад
Boaty McBoat Face
@alikemalulus478
@alikemalulus478 6 месяцев назад
@polytrave
@polytrave 8 месяцев назад
im not a bro but still thanks for the code
@jaypatel0088
@jaypatel0088 7 месяцев назад
Just Code bro 😉😉😉😎😎😎..
@MustafaKaradeniz-yy1cx
@MustafaKaradeniz-yy1cx 19 дней назад
@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
@the_dude_josh
@the_dude_josh 7 месяцев назад
A random comment down below.
@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
@felixconrad9248
@felixconrad9248 2 года назад
Your Videos are Very Helpfull, you Earned your GigaChad-Code-Logo
@notyou3000
@notyou3000 6 месяцев назад
as
@ancestrall794
@ancestrall794 Год назад
Random comment down below
@weary867
@weary867 2 месяца назад
Random
Далее
C# interfaces 🐟
5:38
Просмотров 125 тыс.
Object Oriented Programming - The Four Pillars of OOP
11:23
#kikakim
00:31
Просмотров 11 млн
C# generics ⁉️
5:33
Просмотров 71 тыс.
C# multithreading 🧶
6:59
Просмотров 149 тыс.
4.7: Introduction to Polymorphism - The Nature of Code
8:46
C# Lists 📃
6:46
Просмотров 99 тыс.
C# static 🚫
5:03
Просмотров 67 тыс.
Java Polymorphism Fully Explained In 7 Minutes
7:16
Просмотров 302 тыс.
Fundamental Concepts of Object Oriented Programming
9:16
C++ Polymorphism and Virtual Member Functions [6]
12:13
iPhone 16 - 20+ КРУТЫХ ИЗМЕНЕНИЙ
5:20