Welcome back.
In this video we're going to look at the different types of inheritances.
And there are four types of which C-sharp directly supports three.
So the fourth one is something that is possible or made possible using a little trick or a workaround.
You could say because we're going to look into that later.
But let's start with the first three because they are the easiest ones.
So number one is our inheritance that we have here.
So in our example we have a single inheritance where we have our class animal and then we have our inheriting
class dog.
This is what's called a single inheritance where a class inherits from another class.
But there are no other classes that inherit from that other class.
So that's it.
So this is the depth of inheritance that we have.
However, there is a second layer to it which is called multi-level inheritance.
So coming to our dog example, we could have another animal slash dog, which could be let's say collie
okay.
And that is going to be a dog.
Now this collie or border collie is going to be of type dog and will have its own members.
So its own traits, its own methods and so forth.
Okay, so maybe a collie has this method of being hyperactive just as an example.
Right.
So public void going nuts.
At least that's what my collie always did was active until she turned 8 or 9 years old.
And even then she was giga active until like not giga, but only mega active until she had a surgery
at like 12 or 13 years old.
So now this would be our collie collie going nuts.
Okay.
And Collie, by the way, is a breed of animal or a breed of dog.
Now, in this case, Collie inherits from dog, which means that a collie now has all the traits of
animal as well as of dog.
Okay, so what we have here is the second type of inheritance, which is the multi-level inheritance
where you don't only have one level, but a second level as well, maybe even a third level.
So what we saw with exceptions is that there are so many other layers.
So we looked at exceptions which then had this inheritance called or this derived class called system
exception and so forth.
So all the way to arithmetic exception and then divide by zero exception.
So these were examples of multi-level inheritances.
Now there is another one that is called hierarchy recall inheritance where multiple classes inherit
from one base class.
So if we took away this example of collie okay.
So let's put this further away.
And now we just have another class cat which is also inheriting from animal, which means now cat will
also be able to eat.
Okay.
Now a cat would have this method called meow meow.
I don't sure how to write it correctly in English, but it would be actually, let's do it in German.
Meow.
That's how Germans would write it.
So Cat is meowing.
I think it's meow W right, let's write it like this.
Meowing and the English language just is all over the place when it comes to pronunciation.
So there we are.
Our cat animal is inheriting so this here is called hierarchical inheritance.
So this is the third type of inheritance where you have one base class animal and you have multiple
deriving classes.
So dog is deriving of animal, cat is deriving of animal.
And there could be many many more.
Now you can obviously also combine multi-level with hierarchical inheritance.
Okay.
So we now have a cat that is meowing.
But we could also have a dog that is barking.
But at the same time having a collie that is barking and doing some other stuff and having different
kinds of cats that have different traits and different members, so to speak, when coming back to our
coding, uh, examples here.
Okay.
So you've seen the different layers or types of inheritance.
Now as I said.
There is a fourth one and that is not possible in C sharp.
There are other programming languages where it is possible and that is called multiple inheritance,
where you have the feature of a class where a class can inherit from multiple other classes.
Okay.
Unfortunately, as I said, it's not possible or not, unfortunately, but it's just not not possible
to achieve that directly via inheritance in C sharp.
And that's where interfaces come in and interfaces are for another day.
So they're a very well significantly more complex topic in my opinion at least.
And we're going to cover that later on.
But this is just for you to know.
There are four types.
Three of them are easily accessible or usable in C sharp without any workarounds.
And the fourth one where a class inherits from multiple classes, is only possible through interfaces.
Okay, so that's it for this video.
See you in the next one.