1 00:00:01,020 --> 00:00:04,110 A child class can use the constructor of its parent class. 2 00:00:06,480 --> 00:00:10,320 The child class uses its constructor to update its unique fields. 3 00:00:12,080 --> 00:00:16,610 And the child class uses the parent constructor to update inherited fields. 4 00:00:19,550 --> 00:00:23,690 In this lesson, each child class is going to call the parent copy constructor. 5 00:00:27,400 --> 00:00:34,510 So just a quick revision, super refers to the super class, which also means the parent class and super 6 00:00:34,510 --> 00:00:39,790 rich brackets refers to the constructor of the super class, the constructor of the parent class. 7 00:00:40,870 --> 00:00:46,690 If you want to call the the constructor of a parent class, you super an inside person, the object 8 00:00:46,690 --> 00:00:48,220 you want to copy Fields' from. 9 00:00:49,880 --> 00:00:51,750 So inside main, remove the array. 10 00:00:51,800 --> 00:00:54,800 This was just to show you the flexibility of polymorphism. 11 00:01:10,390 --> 00:01:14,410 And now set another object short to equal to a new copy of shirt. 12 00:01:22,610 --> 00:01:26,690 But that's not going to work yet because we're calling it can't be constructive, it doesn't exist. 13 00:01:27,080 --> 00:01:29,960 So here, copy the first instructor, as always. 14 00:01:32,540 --> 00:01:36,410 And instead of getting values from a bunch of different parameters, we're going to get the values from 15 00:01:36,410 --> 00:01:37,550 a source object. 16 00:01:41,770 --> 00:01:44,770 And inside supercapacitor the source object. 17 00:01:51,610 --> 00:01:54,850 Remember, super with brackets means we're calling a constructor. 18 00:01:55,060 --> 00:02:00,550 So this means we're calling the copy constructor of the parent class parent class doesn't have a copy 19 00:02:00,550 --> 00:02:02,560 constructor yet, so we're to have to create one. 20 00:02:03,190 --> 00:02:04,900 So copy the first one, as always. 21 00:02:04,900 --> 00:02:08,770 And instead of getting values from a bunch of different parameters, we're going to get the values from 22 00:02:08,770 --> 00:02:10,810 a source, object, product source. 23 00:02:21,380 --> 00:02:27,710 And once again, notice the polymorphism, the product copy constructor, expect a product object. 24 00:02:28,720 --> 00:02:30,250 But we're passing in a shirt. 25 00:02:33,840 --> 00:02:38,250 Remember that a class can take its own form or it can take the form of the class it's inheriting from, 26 00:02:38,520 --> 00:02:42,000 in this case, the shirt object is taking the form of a product. 27 00:02:46,420 --> 00:02:49,510 All right, put a break point, let's debugged there in time. 28 00:02:50,760 --> 00:02:52,660 Creates a new object of the short class. 29 00:02:52,680 --> 00:02:56,460 OK, this points to the current object that's being created. 30 00:02:57,840 --> 00:03:00,510 Soares points to the object being passed in. 31 00:03:01,720 --> 00:03:05,350 Here are passing the source object into the parent copy constructor. 32 00:03:10,210 --> 00:03:14,800 There it copies the three fields from the source object into the current one. 33 00:03:22,840 --> 00:03:28,570 And once the parent constructor is done, the child constructor copies the last field from the source 34 00:03:28,570 --> 00:03:31,300 object into the current one, beautiful. 35 00:03:38,070 --> 00:03:40,800 And now what if I want to create a copy of Pentz? 36 00:03:42,580 --> 00:03:45,820 So Serpens to equal to a new copy of the pants object. 37 00:03:52,530 --> 00:03:56,500 But that isn't going to work yet because we're calling a copy constructor that doesn't exist. 38 00:03:56,520 --> 00:04:02,910 So here, copy the first constructor and instead of getting values from a bunch of different parameters, 39 00:04:02,910 --> 00:04:05,160 it's going to get the values from a source object. 40 00:04:08,600 --> 00:04:11,510 So inside, superbrain, a person, the source object. 41 00:04:15,060 --> 00:04:15,840 And that's all. 42 00:04:17,620 --> 00:04:18,459 Run the debugger. 43 00:04:25,570 --> 00:04:29,860 It creates a new object of the pants class, the instructor receives a source object. 44 00:04:33,930 --> 00:04:39,750 Here we're passing the source objecting to the parent copy constructor there, it copies three fields 45 00:04:39,750 --> 00:04:41,790 from the source object into the current one. 46 00:04:47,940 --> 00:04:53,550 And once the parent constructor is done, the child constructor copies of the last field from the source 47 00:04:53,550 --> 00:04:55,080 object into the current one. 48 00:05:04,930 --> 00:05:08,710 Let's recap a child class, can you do the copy constructor of its parent class? 49 00:05:09,960 --> 00:05:15,960 The child uses the parent copy constructor to update inherited fields, and it can use its copy constructor 50 00:05:15,960 --> 00:05:17,580 to update its unique fields.