1 00:00:00,300 --> 00:00:01,360 ‫Welcome back. 2 00:00:01,380 --> 00:00:09,870 ‫I hope you try to finish this challenge where you had to create several classes and subclasses or several 3 00:00:09,870 --> 00:00:11,540 ‫deriving classes. 4 00:00:11,550 --> 00:00:14,040 ‫And yeah, let's just go ahead and start with it. 5 00:00:14,040 --> 00:00:19,170 ‫So let's create a new class called Employee. 6 00:00:22,580 --> 00:00:26,720 ‫And this employee should have several information. 7 00:00:26,720 --> 00:00:36,460 ‫First of all the names so I'm just gonna go ahead and prop and it's going to be a string property with 8 00:00:36,470 --> 00:00:37,310 ‫name. 9 00:00:38,600 --> 00:00:45,710 ‫Then we have another one, prop string, first name. 10 00:00:46,820 --> 00:00:52,060 ‫And the third one is a property called celery. 11 00:00:53,300 --> 00:00:58,640 ‫So now we have those three properties and we can go ahead and create a. 12 00:00:59,910 --> 00:01:12,150 ‫Constructor, public employee, and that one takes in a name, a first name and a salary. 13 00:01:13,170 --> 00:01:15,120 ‫And of course, we need to set those. 14 00:01:15,130 --> 00:01:18,840 ‫So this dot name is going to be named this. 15 00:01:18,840 --> 00:01:21,510 ‫The first name is going to be first name. 16 00:01:21,510 --> 00:01:24,990 ‫And this dot salary is going to be salary. 17 00:01:27,160 --> 00:01:29,620 ‫All right, so that's our constructor. 18 00:01:29,800 --> 00:01:30,640 ‫And then. 19 00:01:31,490 --> 00:01:36,170 ‫Our employee should have methods called work and POS. 20 00:01:36,170 --> 00:01:42,170 ‫So let's create those public void work. 21 00:01:42,920 --> 00:01:48,350 ‫And this should just write somewhere like I am working. 22 00:01:49,640 --> 00:02:02,810 ‫And then one that is a void called pause, which is just going to write something like I am having a 23 00:02:02,810 --> 00:02:03,710 ‫break. 24 00:02:05,780 --> 00:02:08,810 ‫All right, so that's pretty much our employee. 25 00:02:08,810 --> 00:02:16,250 ‫And now we want to inherit from that employee and we want to go ahead and create a new class called 26 00:02:16,250 --> 00:02:17,150 ‫Boss. 27 00:02:18,080 --> 00:02:20,900 ‫So this is going to be both actually. 28 00:02:21,110 --> 00:02:22,610 ‫Let's change that. 29 00:02:22,610 --> 00:02:27,890 ‫Let's just delete this class and create a new one. 30 00:02:27,890 --> 00:02:35,840 ‫We could have renamed it, but creating a new one is more convenient actually boss like that. 31 00:02:35,840 --> 00:02:40,010 ‫And now that boss should have an own property. 32 00:02:41,070 --> 00:02:42,030 ‫As stated here. 33 00:02:42,030 --> 00:02:42,900 ‫So let's go back. 34 00:02:42,900 --> 00:02:49,170 ‫Created your own class boss with a property called Company Car and the method lead. 35 00:02:49,170 --> 00:02:57,690 ‫So let's create those property and this one should be a string and I'm going to call it company car. 36 00:02:59,130 --> 00:03:04,950 ‫And then we have the method public void lead. 37 00:03:06,120 --> 00:03:10,380 ‫And this one's just going to say something like I'm the boss or something like that. 38 00:03:10,650 --> 00:03:13,140 ‫CW Boss. 39 00:03:15,300 --> 00:03:18,510 ‫So great English grammar in here. 40 00:03:18,690 --> 00:03:19,620 ‫I'm boss. 41 00:03:19,830 --> 00:03:28,950 ‫And now we should go ahead and create another driving class of employees called trainees or trainee 42 00:03:28,950 --> 00:03:33,140 ‫with the properties working hours and school hours and the method learn. 43 00:03:33,150 --> 00:03:34,730 ‫So let's just do that. 44 00:03:34,740 --> 00:03:39,360 ‫Let's create a new class called. 45 00:03:43,740 --> 00:03:44,640 ‫Trainee. 46 00:03:47,070 --> 00:03:54,510 ‫And that trainee, by the way, the boss didn't derive from employee, so should just add that employee. 47 00:03:55,050 --> 00:03:57,470 ‫The same goes for our trainee. 48 00:03:57,500 --> 00:04:00,240 ‫It also derives from employee. 49 00:04:00,660 --> 00:04:04,830 ‫And now, as you see, as it does not have a. 50 00:04:07,470 --> 00:04:09,960 ‫As we don't have an empty. 51 00:04:14,190 --> 00:04:15,420 ‫Constructor in here. 52 00:04:15,420 --> 00:04:16,470 ‫It's complaining. 53 00:04:16,470 --> 00:04:26,520 ‫So I'm going to create an empty and structure, which is just going to say the name is going to default 54 00:04:26,820 --> 00:04:35,100 ‫as Dennis, then the first name is going to be defaulted as actually the first name is Dennis. 55 00:04:35,340 --> 00:04:38,760 ‫The last name should be pun Utah in my case. 56 00:04:39,270 --> 00:04:48,030 ‫And then we have the salary, which is just going to be let's keep it simple, 50 grand, not very accurate, 57 00:04:48,030 --> 00:04:51,240 ‫and we don't even talk about the currency. 58 00:04:51,300 --> 00:04:51,690 ‫All right. 59 00:04:51,690 --> 00:04:56,430 ‫So now if we say that, you see the error disappears because if I don't have that. 60 00:04:56,430 --> 00:04:59,480 ‫So just a second, let's get rid of it. 61 00:04:59,670 --> 00:05:02,790 ‫It will or it will be unhappy here. 62 00:05:02,790 --> 00:05:08,820 ‫So you say there is no argument given that corresponds to the required formal parameter name of employee 63 00:05:08,850 --> 00:05:10,590 ‫employee string string int. 64 00:05:12,000 --> 00:05:17,520 ‫So either that or we have to implement a constructor in the boss class. 65 00:05:19,940 --> 00:05:21,660 ‫Which I think we should still do. 66 00:05:21,680 --> 00:05:27,140 ‫So let's do that, because if we create a boss, we want to inform or we want to add the information 67 00:05:27,140 --> 00:05:28,270 ‫about this company car. 68 00:05:28,520 --> 00:05:37,610 ‫So let's create a public boss, which will take a string called company car. 69 00:05:39,080 --> 00:05:49,550 ‫Company car, then a string called name, string called first name and an integer called celery 70 00:05:52,070 --> 00:05:52,550 ‫root. 71 00:05:53,840 --> 00:06:05,060 ‫And now when here we just say something like this dot company car is equal to comp per ne car. 72 00:06:05,420 --> 00:06:07,880 ‫Now all of the other ones are missing. 73 00:06:08,150 --> 00:06:19,490 ‫And we can, of course, go ahead and say something like this dot name is equal to name, but we can 74 00:06:19,490 --> 00:06:23,300 ‫even make it simpler by using something called the base. 75 00:06:23,300 --> 00:06:29,390 ‫So we're using base name, first name and salary. 76 00:06:31,870 --> 00:06:36,310 ‫So what that does is it simply uses the approach that we had here. 77 00:06:36,310 --> 00:06:40,600 ‫So this one here, so it's using this constructor for us. 78 00:06:40,600 --> 00:06:43,840 ‫So we don't have to write all of that initialization in here. 79 00:06:46,380 --> 00:06:48,840 ‫All right, before we do anything else, let's test that. 80 00:06:48,840 --> 00:06:52,020 ‫So let's create an employee. 81 00:06:52,500 --> 00:06:54,990 ‫Or actually, let's create a boss. 82 00:06:56,040 --> 00:06:58,370 ‫So let's go ahead with an employee. 83 00:06:58,380 --> 00:07:02,160 ‫So employee is going to be Michael 84 00:07:04,410 --> 00:07:10,650 ‫my co and he is a new employee and now we could go ahead like that. 85 00:07:10,650 --> 00:07:12,180 ‫So that will be Dennis. 86 00:07:12,180 --> 00:07:21,360 ‫So it will just take this constructor here, but as I prefer to inform about the real Michael, so it's 87 00:07:21,360 --> 00:07:28,140 ‫going to be Michael Miller and his salary is going to be 40,000. 88 00:07:29,730 --> 00:07:33,990 ‫And now we can, of course, go ahead and call methods of Michael. 89 00:07:34,020 --> 00:07:34,890 ‫Michael. 90 00:07:35,310 --> 00:07:40,680 ‫And we had well, he should work, so please go ahead and work. 91 00:07:40,680 --> 00:07:45,000 ‫And Michael, go ahead and make a pass. 92 00:07:47,240 --> 00:07:55,190 ‫And then finally console Todd Reed key in order to keep the console open. 93 00:07:55,430 --> 00:07:56,840 ‫So let's test that. 94 00:07:57,560 --> 00:07:58,520 ‫And we are. 95 00:07:58,550 --> 00:08:03,230 ‫So first he's working and then he's having a break and that's great. 96 00:08:03,530 --> 00:08:04,680 ‫Good guy, Michael. 97 00:08:04,700 --> 00:08:06,730 ‫Now we can go ahead and create a boss. 98 00:08:06,740 --> 00:08:11,600 ‫So let's go ahead and say boss and I'm going to call him. 99 00:08:11,690 --> 00:08:18,490 ‫Chuck Norris is going to be a new boss called. 100 00:08:18,500 --> 00:08:19,990 ‫Well, he needs a company car. 101 00:08:20,000 --> 00:08:27,020 ‫What's it's going to be for Ferrari, then a name. 102 00:08:27,020 --> 00:08:28,700 ‫And this will be Norris. 103 00:08:29,060 --> 00:08:36,140 ‫Then the first name will be Chuck and the salary is going to be over 9000. 104 00:08:36,920 --> 00:08:43,370 ‫So just a very high value and it's actually not accepting that value. 105 00:08:43,400 --> 00:08:46,280 ‫So that was too much for an integer to bear. 106 00:08:46,820 --> 00:08:53,480 ‫So that's a lot of money that Chuck is making and now we can go ahead and make him lead. 107 00:08:53,480 --> 00:08:59,750 ‫So let's Chuck Norris be our leader and he's going to lead. 108 00:08:59,750 --> 00:09:01,400 ‫So let's see what he says. 109 00:09:01,610 --> 00:09:03,650 ‫And he says, I'm boss. 110 00:09:04,460 --> 00:09:09,020 ‫And of course, we can go ahead and add some more information about what he's saying. 111 00:09:11,180 --> 00:09:14,090 ‫My name is. 112 00:09:14,450 --> 00:09:22,100 ‫And then we just use something like his name and you could even add some more information about his 113 00:09:22,100 --> 00:09:23,960 ‫salary, all of those kind of things. 114 00:09:23,960 --> 00:09:27,050 ‫So that was not part of the exercise, but I'm just adding it here. 115 00:09:27,050 --> 00:09:35,090 ‫So we have a little more information about this guy, and I'm going to start with the first name and 116 00:09:35,090 --> 00:09:39,650 ‫then I'm going to go ahead with the last name or actually the name. 117 00:09:41,120 --> 00:09:46,310 ‫And as you can see, I can use them even though I haven't created those properties in my boss because 118 00:09:46,310 --> 00:09:48,830 ‫I'm inheriting them from employee. 119 00:09:48,950 --> 00:09:56,510 ‫And now if we run it again on boss, my name is Chuck Norris and that's awesome. 120 00:09:56,510 --> 00:09:58,340 ‫So Chuck Norris is our boss. 121 00:09:58,340 --> 00:10:08,090 ‫Now, our trainee needs also to do something, so he should have his own properties, which is for one, 122 00:10:08,090 --> 00:10:18,890 ‫his working hours, working hours, and another one which is going to be his study hours or school hours. 123 00:10:19,730 --> 00:10:23,720 ‫So it should be the study hours in the sense of him studying at home. 124 00:10:23,720 --> 00:10:28,040 ‫But actually, I'm not sure whether you are aware about the training system in Germany. 125 00:10:28,040 --> 00:10:35,120 ‫You have a three year training system in which you learn a job and it's similar to well, it's not really 126 00:10:35,120 --> 00:10:41,150 ‫similar to the college, but that's pretty much like after ten years of school, you go there, you 127 00:10:41,150 --> 00:10:45,830 ‫go to this, you study a trainee job, and you do that for three years. 128 00:10:45,830 --> 00:10:51,410 ‫And afterwards, you're an expert, not an expert, but you are well educated to do the job quite well. 129 00:10:51,410 --> 00:10:57,830 ‫So you have like 60% of working time or even 80% of working time and then one day of school. 130 00:10:57,830 --> 00:11:04,850 ‫So you go to school in order to learn more detailed, important information about the task at hand. 131 00:11:05,090 --> 00:11:08,000 ‫And that's something that works quite well for Germany. 132 00:11:08,000 --> 00:11:14,480 ‫So we don't need to everybody to go to university in order to get a good job or everybody to go to college 133 00:11:14,480 --> 00:11:15,440 ‫to get a good job. 134 00:11:15,440 --> 00:11:18,800 ‫So this is quite an alternative there. 135 00:11:19,040 --> 00:11:19,370 ‫All right. 136 00:11:19,370 --> 00:11:29,750 ‫So just a little side note and now let's go ahead and create a trainee constructor and it will need 137 00:11:29,750 --> 00:11:34,130 ‫the working hours, then the school hours, 138 00:11:37,310 --> 00:11:51,110 ‫a name, a first name, string, first name, color like that, I think like this and int salary. 139 00:11:51,260 --> 00:11:53,600 ‫And now here we're using base as well. 140 00:11:53,600 --> 00:11:55,340 ‫And if you didn't do that, that's totally fine. 141 00:11:55,340 --> 00:11:55,970 ‫No worries. 142 00:11:56,210 --> 00:11:58,580 ‫It's just for you to know that you can do that. 143 00:11:58,580 --> 00:12:03,870 ‫So name, first name and salary. 144 00:12:03,870 --> 00:12:13,010 ‫I'm just going to take the ones from our base class and now I just need to assign the working hours. 145 00:12:14,930 --> 00:12:22,670 ‫And actually here I want to have this start working hours, which will be our working hours and then 146 00:12:22,670 --> 00:12:28,790 ‫this dot school hours, which will be our school hours and that's it, right? 147 00:12:28,790 --> 00:12:32,420 ‫Name, first name and salary are from the base class anyways. 148 00:12:32,420 --> 00:12:35,330 ‫And now we need to methods learn. 149 00:12:35,330 --> 00:12:38,270 ‫And what was it. 150 00:12:38,630 --> 00:12:42,740 ‫Learn and work and now work. 151 00:12:43,220 --> 00:12:46,190 ‫The trainee should work slightly differently than the. 152 00:12:46,220 --> 00:12:48,410 ‫Boss or the employee. 153 00:12:48,710 --> 00:12:50,900 ‫So we learn. 154 00:12:51,080 --> 00:12:53,570 ‫And here we just write something like. 155 00:12:54,260 --> 00:13:10,250 ‫CW I'm learning for so many hours like this and it will be the learning hours or school hours. 156 00:13:12,150 --> 00:13:12,810 ‫Like that. 157 00:13:13,080 --> 00:13:21,540 ‫And now the last method will be public void work. 158 00:13:21,990 --> 00:13:29,430 ‫And now this one should actually override our employee method console, dot, right line. 159 00:13:32,250 --> 00:13:39,990 ‫I work for 0 hours. 160 00:13:42,970 --> 00:13:43,900 ‫And by zero. 161 00:13:43,900 --> 00:13:44,940 ‫I don't mean zero. 162 00:13:44,950 --> 00:13:48,550 ‫I mean the working hours. 163 00:13:50,920 --> 00:13:56,950 ‫So now if you see that it says hides inherited member employee work used use new key word if hiding 164 00:13:56,950 --> 00:14:03,250 ‫was intended and that's something that we will cover in detail in the next chapter where we're talking 165 00:14:03,250 --> 00:14:05,170 ‫about polymorphism. 166 00:14:05,170 --> 00:14:14,500 ‫But now let's just create a new employee and this time it's going to be a trainee employee. 167 00:14:14,830 --> 00:14:22,720 ‫So I'm going to call her Michelle and she's going to be the new trainee. 168 00:14:24,040 --> 00:14:27,000 ‫Michelle, actually, she needs working hours. 169 00:14:27,010 --> 00:14:30,100 ‫Let's say she's working for 32 hours a week. 170 00:14:30,100 --> 00:14:32,390 ‫Then she goes to school for 8 hours a week. 171 00:14:32,410 --> 00:14:35,820 ‫Her name is Michelle Gardener. 172 00:14:37,370 --> 00:14:38,000 ‫So. 173 00:14:38,020 --> 00:14:45,850 ‫Michelle and her salary is something like 10,000 a year. 174 00:14:47,380 --> 00:14:47,650 ‫All right. 175 00:14:47,650 --> 00:14:55,060 ‫So now let's go ahead and ask Michelle about her studying. 176 00:14:55,060 --> 00:14:56,200 ‫So how is that going? 177 00:14:56,200 --> 00:14:59,020 ‫And then Michelle, the work. 178 00:15:01,990 --> 00:15:05,900 ‫Now let's run it and you will see what's gonna happen. 179 00:15:05,900 --> 00:15:11,660 ‫And it says, I'm learning for 8 hours and I work for 32 hours. 180 00:15:11,840 --> 00:15:19,430 ‫Well, we have overridden it, and we just used the exact same method. 181 00:15:20,390 --> 00:15:21,350 ‫So work. 182 00:15:21,390 --> 00:15:22,260 ‫Same name. 183 00:15:22,280 --> 00:15:27,710 ‫This one was not virtual and we overrode it. 184 00:15:27,710 --> 00:15:28,970 ‫And here it's complaining. 185 00:15:28,970 --> 00:15:34,490 ‫Or it's not really complaining, but it says that there is something not perfectly right. 186 00:15:34,580 --> 00:15:41,120 ‫So that's perfect because it helps us to go to the next chapter where we talk about polymorphism, about 187 00:15:41,120 --> 00:15:46,460 ‫overriding methods even further, because so far we've only used one approach, but there are multiple 188 00:15:46,460 --> 00:15:46,910 ‫ones. 189 00:15:46,910 --> 00:15:54,680 ‫So if I, for example, create a public new void work that will go ahead and create a new method for 190 00:15:54,680 --> 00:15:55,160 ‫me. 191 00:15:55,490 --> 00:15:58,160 ‫And well, in our case it does the same thing. 192 00:15:58,160 --> 00:16:04,460 ‫But when it comes to polymorphism, this is going to have a huge impact onto our our program. 193 00:16:04,460 --> 00:16:08,000 ‫So I hope you manage to build that. 194 00:16:08,000 --> 00:16:14,840 ‫And it was just a different exercise, just a new exercise, another one for you to test again, whether 195 00:16:14,840 --> 00:16:20,930 ‫you can handle that, whether you can create subclasses and just to get a better understanding of how 196 00:16:20,930 --> 00:16:25,820 ‫classes or the base classes and deriving classes work together and how to build them and stuff like 197 00:16:25,820 --> 00:16:26,240 ‫that. 198 00:16:26,360 --> 00:16:26,840 ‫Great. 199 00:16:26,840 --> 00:16:31,400 ‫So see you in the next chapter where we're going to go into polymorphism.