C# inheritance 👪

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024
  • C# inheritance tutorial example explained
    #C# #inheritance #tutorial
    using System;
    namespace MyFirstProgram
    {
    class Program
    {
    static void Main(string[] args)
    {
    // inheritance = 1 or more child classes recieving fields, methods, etc. from a common parent
    Car car = new Car();
    Bicycle bicycle = new Bicycle();
    Boat boat = new Boat();
    Console.WriteLine(car.speed);
    Console.WriteLine(car.wheels);
    car.go();
    Console.WriteLine(bicycle.speed);
    Console.WriteLine(bicycle.wheels);
    bicycle.go();
    Console.WriteLine(boat.speed);
    Console.WriteLine(boat.wheels);
    boat.go();
    Console.ReadKey();
    }
    }
    class Vehicle
    {
    public int speed = 0;
    public void go()
    {
    Console.WriteLine("This vehicle is moving!");
    }
    }
    class Car : Vehicle
    {
    public int wheels = 4;
    }
    class Bicycle : Vehicle
    {
    public int wheels = 2;
    }
    class Boat : Vehicle
    {
    public int wheels = 0;
    }
    }

Комментарии • 49

  • @BroCodez
    @BroCodez  3 года назад +30

    using System;
    namespace MyFirstProgram
    {
    class Program
    {
    static void Main(string[] args)
    {
    // inheritance = 1 or more child classes recieving fields, methods, etc. from a common parent
    Car car = new Car();
    Bicycle bicycle = new Bicycle();
    Boat boat = new Boat();
    Console.WriteLine(car.speed);
    Console.WriteLine(car.wheels);
    car.go();
    Console.WriteLine(bicycle.speed);
    Console.WriteLine(bicycle.wheels);
    bicycle.go();
    Console.WriteLine(boat.speed);
    Console.WriteLine(boat.wheels);
    boat.go();
    Console.ReadKey();
    }
    }
    class Vehicle
    {
    public int speed = 0;
    public void go()
    {
    Console.WriteLine("This vehicle is moving!");
    }
    }
    class Car : Vehicle
    {
    public int wheels = 4;
    }
    class Bicycle : Vehicle
    {
    public int wheels = 2;
    }
    class Boat : Vehicle
    {
    public int wheels = 0;
    }
    }

  • @Millequattro
    @Millequattro Год назад +38

    I LOVE your 4 minutes videos, your channel is totally underrated

    • @urmomlolgottem
      @urmomlolgottem 6 месяцев назад

      I don't think being the King is underrated

  • @avinashparab1220
    @avinashparab1220 Год назад +3

    Your knowledge and the way you are explaining it.. It's an amazing❤

  • @zarifahmed5192
    @zarifahmed5192 2 года назад +4

    This is the best coding channel, it has giga chad

  • @user-iq2zr8vx1s
    @user-iq2zr8vx1s Год назад +3

    Great explainations!
    i see few do like this:
    Vehicle boat = new boat();
    and not like you do:
    Boat boat = new boat();
    why use
    parentclass v = new childclass();
    or
    childclass v = new childclass();

    • @IsRaphaelGo
      @IsRaphaelGo 16 часов назад

      My best guess would be that since it's the parent just like the children have access to the parent and its code it goes the same for the parent meaning it can summon them to create a new object

  • @KarmsJooo
    @KarmsJooo День назад

    wow this helps me a lot❤

  • @tupll997
    @tupll997 Год назад

    Bro you explain stuff in 4 min so i get it i its crazy pls keep doing these videos

  • @skhasanalsahib
    @skhasanalsahib Год назад

    I find your videos to be very helpful. Thanks a lot, I really appreciate it!

  • @noluthandozama6652
    @noluthandozama6652 Год назад +1

    absolutely amazing thank you I needed this.

  • @adambosick3137
    @adambosick3137 6 месяцев назад

    Please make a video on delegates. I understand it, don't use it, but think it would be helpful for others. :)

  • @kartakartak
    @kartakartak Год назад +1

    Very well explained!

  • @moseskawli7097
    @moseskawli7097 Год назад

    Well explain inheritance. Love it.

  • @gabrielalicea4803
    @gabrielalicea4803 7 месяцев назад

    Great explanation. ❤

  • @johng6417
    @johng6417 Год назад

    woot woot!

  • @dominichoevenagel
    @dominichoevenagel 2 года назад +1

    You have good clear explained short videos.

  • @area1to1
    @area1to1 8 дней назад

    Brillent

  • @marine2oorah4u15
    @marine2oorah4u15 26 дней назад

    Can you fit multiple parent elements to be used in child classes?

  • @emmanuelmiako5161
    @emmanuelmiako5161 Год назад

    I like it, Picasso!

  • @spartanranger
    @spartanranger 3 года назад

    Thanks for the video Bro.

  • @kmadhavi5854
    @kmadhavi5854 Год назад

    Amazing video sir 🤗

  • @mahrezlol
    @mahrezlol Год назад

    nice!

  • @user-pc7px7em5z
    @user-pc7px7em5z 2 года назад

    תודה

  • @the_3d_cookie
    @the_3d_cookie Год назад

    Thanks bro

  • @noxagen
    @noxagen 3 года назад

    awesome work, u rox

  • @umutkilexter9351
    @umutkilexter9351 Год назад

    teşekkür ederim

  • @rfbu
    @rfbu 2 года назад

    i like it concise

  • @zanagi
    @zanagi 5 месяцев назад

    can you do currentVehicle = car; like c++?

  • @oangtuxuhoaqua
    @oangtuxuhoaqua 2 года назад

    thanks bro

  • @matzedrizzi6222
    @matzedrizzi6222 Год назад

    Please add an explanation on how constructors work in inheritance

    • @toomuchtime4896
      @toomuchtime4896 Год назад +1

      They're the same as outside of inheritance.

  • @SadkGel
    @SadkGel 11 месяцев назад

    hocam KRALSIN

  •  3 года назад

    Thanks Bro!

  • @LucParent905
    @LucParent905 3 года назад

    thanks

  • @__random_variable
    @__random_variable 2 года назад

    nice

  • @budderrar5751
    @budderrar5751 Год назад

    noice

  • @DepixColdtrain
    @DepixColdtrain Год назад

    good video amogus

  • @tylerdonteo5063
    @tylerdonteo5063 Год назад

    This is definitely Chad activity here. This needs to to studied.

  • @zdspider6778
    @zdspider6778 Год назад

    Aren't you supposed to mark the functions you want to override as "virtual"?
    Or is that just a C++ thing and not present in C#?

  • @whitedinamo
    @whitedinamo 2 года назад

    lesson check😇

  • @Try-Until-You-Die
    @Try-Until-You-Die Год назад

    How can you write Console .writeline when you write cw

  • @MrEastgalaxy
    @MrEastgalaxy Год назад

    BRO!

  • @Frigol33tGaming
    @Frigol33tGaming 7 месяцев назад

    Random comment

  • @the_dude_josh
    @the_dude_josh 8 месяцев назад

    A random down below comment.

  • @user-so6pp9iq5y
    @user-so6pp9iq5y 4 месяца назад

    JESUS IS KING

  • @ment_a
    @ment_a 10 месяцев назад

    bro code's unique weakness is spelling

  • @munupixi9840
    @munupixi9840 Год назад

    и ну да