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;
}
}
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;
}
}
I LOVE your 4 minutes videos, your channel is totally underrated
I don't think being the King is underrated
Your knowledge and the way you are explaining it.. It's an amazing❤
This is the best coding channel, it has giga chad
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();
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
wow this helps me a lot❤
Bro you explain stuff in 4 min so i get it i its crazy pls keep doing these videos
I find your videos to be very helpful. Thanks a lot, I really appreciate it!
absolutely amazing thank you I needed this.
Please make a video on delegates. I understand it, don't use it, but think it would be helpful for others. :)
Very well explained!
Well explain inheritance. Love it.
Great explanation. ❤
woot woot!
You have good clear explained short videos.
Brillent
Can you fit multiple parent elements to be used in child classes?
I like it, Picasso!
Thanks for the video Bro.
Amazing video sir 🤗
nice!
תודה
Thanks bro
awesome work, u rox
teşekkür ederim
i like it concise
can you do currentVehicle = car; like c++?
thanks bro
Please add an explanation on how constructors work in inheritance
They're the same as outside of inheritance.
hocam KRALSIN
Thanks Bro!
thanks
nice
noice
good video amogus
This is definitely Chad activity here. This needs to to studied.
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#?
lesson check😇
How can you write Console .writeline when you write cw
write: "cw" and then press tab
BRO!
Random comment
A random down below comment.
JESUS IS KING
bro code's unique weakness is spelling
и ну да