1 00:00:00,410 --> 00:00:03,340 An abstract method can be implemented in many different ways. 2 00:00:05,170 --> 00:00:09,670 If a parent defines an abstract method, the child class is forced to override its. 3 00:00:12,560 --> 00:00:14,720 In this lesson, you will define an abstract method. 4 00:00:17,610 --> 00:00:21,210 An abstract method forces a child class to override its. 5 00:00:22,740 --> 00:00:27,180 Create an abstract method if you want to force every child class to override its. 6 00:00:29,290 --> 00:00:32,619 You can create an abstract method by specifying the level of access. 7 00:00:34,390 --> 00:00:37,880 That it's abstract, which means it can be implemented in many different ways. 8 00:00:37,900 --> 00:00:39,040 It's not concrete. 9 00:00:40,810 --> 00:00:42,850 The return type and parameters. 10 00:00:46,780 --> 00:00:51,710 So as per the requirements, every product needs to be folded before being sold to a customer. 11 00:00:52,210 --> 00:00:57,760 So we need to somehow force every class that is a child of product to implement the fold method. 12 00:00:59,480 --> 00:01:02,210 So right here, we're going to define a public abstract method. 13 00:01:03,860 --> 00:01:10,100 And we're going to force every child past the A method that returns void called foaled, and that receives 14 00:01:10,100 --> 00:01:11,030 no parameters. 15 00:01:12,110 --> 00:01:17,330 Now, an abstract method doesn't have a body because it's not concrete, abstract means the method can 16 00:01:17,330 --> 00:01:22,730 be implemented in many different ways and each child class is going to have its own way of overwriting 17 00:01:22,730 --> 00:01:23,330 this method. 18 00:01:23,840 --> 00:01:27,280 Shirts have one way of being folded and pens up another way. 19 00:01:28,010 --> 00:01:30,910 So inside the short class, notice we've got a compilation error. 20 00:01:31,220 --> 00:01:33,710 We're being forced to override the Fulda method. 21 00:01:39,500 --> 00:01:42,500 And to fold a t shirt first, I'll put four print statements. 22 00:01:47,240 --> 00:01:49,670 First, you have to lay the shirt on a flat surface. 23 00:01:56,980 --> 00:01:58,600 Fold the shirt sideways. 24 00:02:03,720 --> 00:02:04,830 Bring the slaves in. 25 00:02:09,220 --> 00:02:10,889 And fold from the bottom up. 26 00:02:16,010 --> 00:02:21,860 OK, now inside the pants class, once again, notice we get a compilation error, we're being forced 27 00:02:21,860 --> 00:02:23,270 to override the fold method. 28 00:02:33,100 --> 00:02:35,860 And default pants hold pants upright. 29 00:02:40,260 --> 00:02:41,780 Fold one leg over the other. 30 00:02:50,230 --> 00:02:52,480 Fold pens from the bottom in thirds. 31 00:02:57,370 --> 00:02:58,060 And that's it. 32 00:02:58,090 --> 00:03:02,210 Each child overrides the four day method and provides its own implementation. 33 00:03:02,770 --> 00:03:04,240 Let's test everything out in main. 34 00:03:07,800 --> 00:03:10,110 Called Foaled from Schertz Runit. 35 00:03:14,970 --> 00:03:17,430 Called Foaled from Pentz Runit. 36 00:03:18,610 --> 00:03:19,420 And good. 37 00:03:22,480 --> 00:03:25,810 An abstract, a method forces a child class to override its. 38 00:03:27,790 --> 00:03:32,140 You should create an abstract method if you want to force every child class to override its. 39 00:03:35,300 --> 00:03:38,630 You can read an abstract method by specifying the level of access. 40 00:03:40,630 --> 00:03:47,230 That it's abstract, abstract means the method can be implemented in many different ways and each child 41 00:03:47,230 --> 00:03:50,230 class is going to have its own way of overriding this method. 42 00:03:52,260 --> 00:03:54,480 The return type and parameters.