Now, let's look at two more concepts nested class and in a class, and we are going to need them later
on.
So let's look at the concepts here, a class which is created inside another class and a class which
is created inside another class with the key word inner.
So this is the difference between the two.
But there are a little more differences that we need to look at.
So let's look at the master class first in the class.
Such a class which is created inside another class in another class is by default static so its data
members and member functions can be accessed without creating an object of the class.
So without having to create an object of this nesto class, you can go ahead and use the functions and
members.
Then the class cannot access the data.
Members of the outer class.
So it's a one way relationship.
So only the upper class can access the members of the master class, but not the other way around.
So let's look at this.
We have a class called our class and then inside of this class we create another class called Master
Class.
OK, and usually you should create classes which are separated so each having their own file, but sometimes
it just makes sense to have an asset class.
For example, if you really just need its functionality within the hour class that we're using here,
and this is classic example that we see here, is that we have this upper class and there we have a
variable called name and it said to Mr X and then we have this class which has a description and then
it has an ID, which is of type int at a function called Foo, which just prints the name and the ID,
and then we go to our main function where we try to access the description.
So in order to access the description, we go to our outer class and then inside of that we go to the
next class.
So we're accessing the property here and then we create an object of the class and we access the function.
So the function of that master class, so the output is code inside the NSA class and it is one on one.
So now let's look at the inner class concept.
And in a class is a class which is created inside another class with the key word inner.
In other words, we can say that the NSA class, which is marked as inner, is called an inner class.
So it's still an asset class, but it has this additional keyword.
Right.
But the difference now is an upper class cannot be declared inside interfaces or noninsured asset classes.
And the advantage of inner classes is that they are able to access members of its outer class even though
they are private.
So this is the huge difference, right.
So the inner class keeps a reference to an object of its our class.
So if we look at this example here, this is the syntax of an inner class.
So we have the upper class and we have this master class, but we add the inner key word so inner just
before the class keyboard.
All right.
And then if we look at this example that we had before, the only difference now is that we add in a
key word here to our inner class and that we now can access name and ID.
We could, of course, beforehand access the ID anyways, but we couldn't access the name.
So you can see here the name that we're using is from the outer class.
So here where we have this private key word, even so we say, OK, this is private.
So it should only be available within this class.
But with the inner classes, you actually have access to even private class members of the outer class.
OK, so that's the huge difference in another class without this inner key word.
This wouldn't be possible.
So sometimes it just makes sense.
And sometimes you just need this functionality and then you make it in a class and you can use it.
So going back to our function name here we have our outer class inner class description so we can access
the property as we did before, and we can also access the object fool.
So we create an object of the inner class which is inside of our outer class, and then we can go ahead
and use its member functions.
So the output here is code inside in a class name is Mr X and it is one on one.
So we didn't have this name is Mr X before.
All right, so that's it for now, let's get back to where we are actually going to use this functionality
and then we'll make a lot more sense because it's a little bit abstract to look at it that way.
So let's get it into coding.