C# inheritance 👪

preview_player
Показать описание
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.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;
}
}
Рекомендации по теме
Комментарии
Автор

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();



car.go();



bicycle.go();



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;
}
}

BroCodez
Автор

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

Millequattro
Автор

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

avinashparab
Автор

This is the best coding channel, it has giga chad

zarifahmed
Автор

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();

iqzrvxs
Автор

absolutely amazing thank you I needed this.

noluthandozama
Автор

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

skhasanalsahib
Автор

You have good clear explained short videos.

dominichoevenagel
Автор

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

tupll
Автор

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

adambosick
Автор

Please add an explanation on how constructors work in inheritance

matzedrizzi
Автор

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

marineoorahu
Автор

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

zanagi
Автор

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

tylerdonteo
Автор

How can you write Console .writeline when you write cw

Try-Until-You-Die
Автор

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#?

zdspider