1 00:00:00,540 --> 00:00:05,760 Now, let's focus two more concepts nested class and in a class, and we're going to need them later 2 00:00:05,760 --> 00:00:06,030 on. 3 00:00:06,060 --> 00:00:07,740 So let's look at the concepts here. 4 00:00:08,010 --> 00:00:13,180 A class which is created inside another class and a class which is created inside another class with 5 00:00:13,180 --> 00:00:14,130 the key word inner. 6 00:00:14,400 --> 00:00:19,530 So this is the difference between the two, but there are a little more differences that we need to 7 00:00:19,530 --> 00:00:19,860 look at. 8 00:00:20,250 --> 00:00:22,050 So let's look at the master class. 9 00:00:22,050 --> 00:00:28,680 First in the class is such a class which is created inside another class in Scotland. 10 00:00:28,680 --> 00:00:30,600 An asset class is by default static. 11 00:00:31,320 --> 00:00:36,630 So its data members and no functions can be accessed without creating an object of the class. 12 00:00:37,080 --> 00:00:44,880 So without having to create an object of this nested class, you can go ahead and use the functions 13 00:00:45,000 --> 00:00:45,660 and members. 14 00:00:46,260 --> 00:00:52,740 Then the asset class cannot access data on members of the outer class, so it's a one way relationship. 15 00:00:53,040 --> 00:00:59,730 So only the poorer class can access the members of the master class, but not the other way around. 16 00:01:00,600 --> 00:01:05,430 So let's look at this we have a class called our class, and then inside of this class we create another 17 00:01:05,430 --> 00:01:06,750 class called master class. 18 00:01:07,260 --> 00:01:07,710 OK. 19 00:01:07,980 --> 00:01:13,740 And usually you should create classes which are separated so each having their own file. 20 00:01:13,920 --> 00:01:16,470 But sometimes it just makes sense to have a nested class. 21 00:01:16,740 --> 00:01:23,550 For example, if you really just need it's functionality within the upper class that we're using here, 22 00:01:23,970 --> 00:01:29,160 and this is class example that we see here is that we have this other class and there we have a variable 23 00:01:29,160 --> 00:01:30,450 called name. 24 00:01:30,780 --> 00:01:32,550 And it said that to Mr. X. 25 00:01:32,940 --> 00:01:39,960 And then we have this business class, which has a description, and then it has an ID, which is of 26 00:01:39,960 --> 00:01:44,420 type and at a function called Foom, which just prints the name and the ID. 27 00:01:45,720 --> 00:01:51,390 And then we go to our main function where we try to access the description. 28 00:01:51,720 --> 00:01:58,350 So in order to access the description, we go to our outer class and then inside of that, we go to 29 00:01:58,350 --> 00:01:58,980 the nascita. 30 00:01:59,100 --> 00:02:05,190 So we're accessing the property here, and then we create an object of the asset class and we access 31 00:02:05,460 --> 00:02:06,360 the function. 32 00:02:06,570 --> 00:02:09,120 So the function of that master class. 33 00:02:09,780 --> 00:02:12,900 So the output is code inside the NSA class and it is one on one. 34 00:02:14,040 --> 00:02:19,230 So now let's look at the inner class concept, and in a class is a class which is created inside another 35 00:02:19,230 --> 00:02:20,580 class with the keyboard inner. 36 00:02:20,970 --> 00:02:26,160 In other words, we can say that the NSA class, which is marked as inner, is called an inner class. 37 00:02:26,460 --> 00:02:30,510 So it's still an asset class, but it has this additional keyword, right? 38 00:02:31,170 --> 00:02:37,050 But the difference now is and in a class cannot be declared inside interfaces or in asset classes. 39 00:02:37,410 --> 00:02:44,130 And the advantage of in our classes is that they are able to access members of its outer class even 40 00:02:44,130 --> 00:02:45,600 though they are private. 41 00:02:46,200 --> 00:02:47,970 So this is a huge difference, right? 42 00:02:48,240 --> 00:02:51,930 So the inner class keeps a reference to an object of its outer class. 43 00:02:52,650 --> 00:02:56,030 So if you look at this example here, this is the syntax of an inner class. 44 00:02:56,030 --> 00:03:00,210 So we have the upper class and we have dismissed the class, but we add the inner keyword. 45 00:03:00,240 --> 00:03:02,940 So in there just before the class keyword? 46 00:03:03,810 --> 00:03:04,140 All right. 47 00:03:04,170 --> 00:03:06,810 And then if we look at this example that we had before. 48 00:03:07,110 --> 00:03:15,060 The only difference now is that we add in a keyword here to our in a class and that we now can access 49 00:03:15,060 --> 00:03:16,560 name and ID. 50 00:03:16,680 --> 00:03:23,220 We could, of course, beforehand access the idea anyways, but we couldn't access the name. 51 00:03:23,550 --> 00:03:28,460 So you can see here the name that we're using is from the outer class. 52 00:03:28,470 --> 00:03:33,060 So here where we have this private keyword, even so, we say, OK, this is private, so it should 53 00:03:33,060 --> 00:03:35,430 only be available within this class. 54 00:03:35,700 --> 00:03:44,340 But with the inner classes, you actually have access to even private class members of your class. 55 00:03:44,470 --> 00:03:49,530 OK, so that's the huge difference in an asset class without this inner keyword. 56 00:03:50,340 --> 00:03:51,390 This wouldn't be possible. 57 00:03:51,900 --> 00:03:56,160 So sometimes it just makes sense, and sometimes you just need this functionality and then you make 58 00:03:56,160 --> 00:03:57,480 it into the class and you can use it. 59 00:03:58,470 --> 00:04:05,550 So going back to our function mean here we have our outer class in our class description so we can access 60 00:04:05,550 --> 00:04:10,560 the property as we did before and can also access the object form. 61 00:04:11,130 --> 00:04:18,660 So we'll create an object of that in our class, which is inside of our outer class, and then we can 62 00:04:18,660 --> 00:04:20,820 go ahead and use its member functions. 63 00:04:21,240 --> 00:04:25,860 So the output here is code inside in a class name is Mr. X, and it's one one. 64 00:04:26,130 --> 00:04:29,190 So we didn't have this name is Mr. X before. 65 00:04:31,720 --> 00:04:32,980 All right, so that's it for now. 66 00:04:33,370 --> 00:04:38,530 Let's get back to ccording, where we are actually going to use this functionality and then we'll make 67 00:04:38,530 --> 00:04:43,030 a lot more sense because it's a little bit abstract to look at it that way. 68 00:04:43,420 --> 00:04:44,950 So let's get into coding.