1
00:00:00,540 --> 00:00:05,790
Now, let's look at two more concepts nested class and in a class, and we are going to need them later

2
00:00:05,790 --> 00:00:06,040
on.

3
00:00:06,060 --> 00:00:11,160
So let's look at the concepts here, a class which is created inside another class and a class which

4
00:00:11,160 --> 00:00:14,130
is created inside another class with the key word inner.

5
00:00:14,370 --> 00:00:16,350
So this is the difference between the two.

6
00:00:16,530 --> 00:00:19,870
But there are a little more differences that we need to look at.

7
00:00:20,220 --> 00:00:23,450
So let's look at the master class first in the class.

8
00:00:23,500 --> 00:00:32,100
Such a class which is created inside another class in another class is by default static so its data

9
00:00:32,110 --> 00:00:36,670
members and member functions can be accessed without creating an object of the class.

10
00:00:37,080 --> 00:00:45,330
So without having to create an object of this nesto class, you can go ahead and use the functions and

11
00:00:45,330 --> 00:00:45,690
members.

12
00:00:46,260 --> 00:00:48,460
Then the class cannot access the data.

13
00:00:48,480 --> 00:00:50,220
Members of the outer class.

14
00:00:50,220 --> 00:00:52,790
So it's a one way relationship.

15
00:00:53,040 --> 00:00:59,760
So only the upper class can access the members of the master class, but not the other way around.

16
00:01:00,570 --> 00:01:01,470
So let's look at this.

17
00:01:01,470 --> 00:01:06,390
We have a class called our class and then inside of this class we create another class called Master

18
00:01:06,390 --> 00:01:06,780
Class.

19
00:01:07,260 --> 00:01:14,690
OK, and usually you should create classes which are separated so each having their own file, but sometimes

20
00:01:14,700 --> 00:01:16,500
it just makes sense to have an asset class.

21
00:01:16,770 --> 00:01:23,580
For example, if you really just need its functionality within the hour class that we're using here,

22
00:01:23,940 --> 00:01:28,830
and this is classic example that we see here, is that we have this upper class and there we have a

23
00:01:28,830 --> 00:01:37,530
variable called name and it said to Mr X and then we have this class which has a description and then

24
00:01:37,530 --> 00:01:44,610
it has an ID, which is of type int at a function called Foo, which just prints the name and the ID,

25
00:01:45,720 --> 00:01:51,400
and then we go to our main function where we try to access the description.

26
00:01:51,690 --> 00:01:58,440
So in order to access the description, we go to our outer class and then inside of that we go to the

27
00:01:58,460 --> 00:01:59,060
next class.

28
00:01:59,100 --> 00:02:06,370
So we're accessing the property here and then we create an object of the class and we access the function.

29
00:02:06,570 --> 00:02:12,910
So the function of that master class, so the output is code inside the NSA class and it is one on one.

30
00:02:14,040 --> 00:02:16,020
So now let's look at the inner class concept.

31
00:02:16,710 --> 00:02:20,590
And in a class is a class which is created inside another class with the key word inner.

32
00:02:20,970 --> 00:02:26,180
In other words, we can say that the NSA class, which is marked as inner, is called an inner class.

33
00:02:26,430 --> 00:02:30,270
So it's still an asset class, but it has this additional keyword.

34
00:02:30,270 --> 00:02:30,560
Right.

35
00:02:31,140 --> 00:02:37,080
But the difference now is an upper class cannot be declared inside interfaces or noninsured asset classes.

36
00:02:37,410 --> 00:02:44,550
And the advantage of inner classes is that they are able to access members of its outer class even though

37
00:02:44,700 --> 00:02:45,640
they are private.

38
00:02:46,200 --> 00:02:48,000
So this is the huge difference, right.

39
00:02:48,210 --> 00:02:51,960
So the inner class keeps a reference to an object of its our class.

40
00:02:52,650 --> 00:02:56,030
So if we look at this example here, this is the syntax of an inner class.

41
00:02:56,040 --> 00:03:01,620
So we have the upper class and we have this master class, but we add the inner key word so inner just

42
00:03:01,620 --> 00:03:02,920
before the class keyboard.

43
00:03:03,750 --> 00:03:04,150
All right.

44
00:03:04,170 --> 00:03:09,990
And then if we look at this example that we had before, the only difference now is that we add in a

45
00:03:09,990 --> 00:03:16,710
key word here to our inner class and that we now can access name and ID.

46
00:03:16,740 --> 00:03:23,210
We could, of course, beforehand access the ID anyways, but we couldn't access the name.

47
00:03:23,550 --> 00:03:28,480
So you can see here the name that we're using is from the outer class.

48
00:03:28,500 --> 00:03:32,670
So here where we have this private key word, even so we say, OK, this is private.

49
00:03:32,670 --> 00:03:35,460
So it should only be available within this class.

50
00:03:35,700 --> 00:03:44,400
But with the inner classes, you actually have access to even private class members of the outer class.

51
00:03:44,460 --> 00:03:49,560
OK, so that's the huge difference in another class without this inner key word.

52
00:03:50,340 --> 00:03:51,410
This wouldn't be possible.

53
00:03:51,870 --> 00:03:53,400
So sometimes it just makes sense.

54
00:03:53,400 --> 00:03:57,480
And sometimes you just need this functionality and then you make it in a class and you can use it.

55
00:03:58,470 --> 00:04:05,580
So going back to our function name here we have our outer class inner class description so we can access

56
00:04:05,580 --> 00:04:10,580
the property as we did before, and we can also access the object fool.

57
00:04:11,100 --> 00:04:19,170
So we create an object of the inner class which is inside of our outer class, and then we can go ahead

58
00:04:19,170 --> 00:04:20,870
and use its member functions.

59
00:04:21,209 --> 00:04:25,910
So the output here is code inside in a class name is Mr X and it is one on one.

60
00:04:26,100 --> 00:04:29,190
So we didn't have this name is Mr X before.

61
00:04:31,660 --> 00:04:37,450
All right, so that's it for now, let's get back to where we are actually going to use this functionality

62
00:04:37,450 --> 00:04:43,090
and then we'll make a lot more sense because it's a little bit abstract to look at it that way.

63
00:04:43,390 --> 00:04:44,980
So let's get it into coding.

