The noble house of Coteland's in the Kingdom of Coteland's, there was a noble house known as the House
of Base Class.
This house had many ancestral traits and traditions.
Over time, the younger generations.
So the subclasses inherited these traits but also added their unique characteristics.
Lady primary, the matriarch of the House of base class, had two children, Sir Secondary and Lady
Tertiary.
While they both inherited the core values and traditions of House base class, each also brought their
unique flair.
Sir secondary was known for his skills in archery and Lady territory had a melodious voice.
So now let's look at this in a little project.
Okay, I'm going to create a new project and I'm going to select no activity here.
This one will be inheritance app.
And the only thing it does is going to be basic Kotlin code, because I really want to focus on the
concepts of inheritance in this video.
All right.
Therefore let's go ahead.
And once the application is loaded let's go ahead and create a new Kotlin file class and file.
And I'm going to call this one start okay.
This will just be the start.
So this is basically where everything starts.
And we just have our function main.
And this is the starting point of our application.
Now let's go ahead and create a new Kotlin file class.
But this time a class.
And I'm going to call this one base class okay.
Now this base class is what the other classes are going to inherit from.
And then we're going to create another class.
And I'm going to call this one secondary okay.
Like so.
Or you could also call it child class or the base class being the parent class.
The secondary being the child class.
So basically inheritance works that you pass down from the base class.
You pass down the traits as well as the skills.
So the properties as well as the functions.
So how can we check that?
Well it's very simple actually.
Let's go ahead and say here we have a function that has the core values like so.
And the only thing that it does is it just prints out core values of house base class and whatever those
values are.
Right.
We don't know exactly, but that's really not the point.
Now if secondary wants to inherit from base class, we need to use colon and then the name of the class
we want to inherit from, and then the rounded brackets.
Now you see that you cannot just inherit any given class.
A class has to have the open keyword.
So we need to make sure that this base class is open.
So we need to open it up by adding the open keyword just before the class keyword.
And now this error will disappear.
So now let's go ahead and create an object of our base class.
So.
File object one will be an object of base class like so.
And now we can use object dot.
Object one dot and call the core values.
Let's run this code and we will see that we get the core values of base class.
It will print it out onto our console.
And as always, I have to run it twice because I get an error first.
But then you can see I get core values of house base class.
Now let's go ahead and create another object.
And I'm going to call this one object two because it will just be of secondary.
All right.
And now what do I want to apply on this object two.
So I want to call the core values function of the object two.
So of the secondary class.
Let's go ahead and run it again.
And you will see that we will get core values of house base class twice.
Why is that.
Well the thing is the first one is we call the core values function of the base class.
And the second one is we call the core values for our object two of the secondary class.
But now you might say wait a second.
In the secondary class I didn't have any functions.
I didn't set anything up.
This class is empty.
There's nothing in there.
Well, yes and no.
So yes, the class is empty, but it inherits from base class.
And every single function that we created inside of base class can now also be called on the secondary
class objects.
So while the core values were inside of base class they also still exist in secondary.
So when we come back to our noble house of code lands, we have the parent that is the base class,
and she has these core values, and she passes on those core values to her children.
And that is basically one aspect of inheritance.
Now there are multiple aspects of inheritance, and we're going to look at them one by one.
But now this will make a little more sense whenever we are using main activity.
Well our main activity for example, you can see it inherits from some type of activity.
And this just shows that now our main activity is going to behave like this other activity.
But then it's going to add some features to it.
But there is more to that.
So there are things like overriding functions.
That is something we're going to look in the next video at.