WEBVTT 00:07.420 --> 00:13.730 In this video you're going to learn inheritance in E6 using extends and super. 00:14.260 --> 00:22.710 So let's create a new class and then make that class inherits from our first class phone. 00:22.720 --> 00:27.090 6 So let's call this new class 00:30.430 --> 00:34.450 smartphone 6. 00:35.170 --> 00:45.360 So let's give it a constructor which takes the make model an operating system and sets these 00:50.350 --> 00:52.440 says the properties using these values. 01:03.510 --> 01:04.970 All right. 01:05.100 --> 01:15.060 So now we want smartphone 6 to inherit everything from phone 6 no in iOS 5. 01:15.090 --> 01:16.320 You could do something like 01:21.580 --> 01:24.520 phone six dot call. 01:24.550 --> 01:32.440 So use the call method to specify the value of this which will be the instance of this class. 01:32.440 --> 01:40.840 And then you pass the promises you want to pass so that you run the constructor code of the superclass. 01:41.050 --> 01:41.580 All right. 01:41.610 --> 01:44.960 So if you run that code you have to do something like this. 01:45.150 --> 01:45.450 Right. 01:45.480 --> 01:51.270 And then you pass the parameters so in our case we'd have passed only the make and the model like that's 01:52.760 --> 01:58.320 and we would have inherited the warranty color and everything else. 01:58.490 --> 01:59.500 Right. 01:59.540 --> 02:02.750 So everything else you find in the constructor of the superclass. 02:02.750 --> 02:08.310 So you could get rid of this leave only that line and use this in. 02:08.310 --> 02:12.130 Yes right now in iOS 6 you can. 02:12.200 --> 02:15.170 You can do this in a more simpler in a simpler way. 02:15.650 --> 02:22.470 So we will get rid of those two lines because we have called the make and model in the constructor of 02:22.470 --> 02:26.900 the superclass and we will use a function called super. 02:26.970 --> 02:36.450 So this function if you call it's like that's when you pass the make animal javascript. 02:36.480 --> 02:45.480 Now is going to look for the class or the superclass from which you are inheriting or trying to inherit 02:45.840 --> 02:50.300 properties and methods in the constructor. 02:50.370 --> 02:55.070 Now you need to specify what the superclass is. 02:55.160 --> 02:55.520 Okay. 02:55.620 --> 03:01.070 Because we haven't said anywhere that we want to inherit from phone 6 or the class forensics. 03:01.230 --> 03:09.110 So you need to use the extents keyword like that's followed by the name of the superclass. 03:09.140 --> 03:15.530 So if you try this then you have you inherit everything that you find in the constructor of the superclass 03:16.010 --> 03:25.540 basically you just running this code with this set to the instance of the new class or subclass. 03:25.540 --> 03:25.840 All right. 03:27.490 --> 03:35.950 Now let's say that you of course also an extended warranty in this new cars and you want to use the 03:35.950 --> 03:38.490 same extend warranty of the superclass. 03:38.650 --> 03:45.640 So all you need to do is call super dots the extend the warranty of the superclass like that. 03:46.690 --> 03:50.140 This will work perfectly. 03:50.270 --> 03:50.530 All right. 03:50.900 --> 03:51.680 So let's try this. 03:51.680 --> 03:56.450 So let's create a new instance of smartphone 04:04.900 --> 04:07.240 so let's give it a make 04:10.930 --> 04:12.500 model. 04:13.030 --> 04:14.050 The operating system 04:17.490 --> 04:24.100 terrorists log it's. 04:24.210 --> 04:25.180 So this is what you get. 04:25.200 --> 04:27.180 So you can see the make model 04:32.720 --> 04:40.160 and also you can see the warranty color the log and so on. 04:40.160 --> 04:43.150 So this has been have been inherited. 04:43.150 --> 04:48.110 All right from the superclass. 04:48.530 --> 04:49.640 Now if you try 04:56.180 --> 04:57.160 extend the warranty 05:03.160 --> 05:06.460 by 10 and you logs again 05:12.310 --> 05:12.830 it works. 05:12.850 --> 05:16.970 So it's jumped from 24 to 34 right now. 05:17.230 --> 05:26.770 If you check whether smartphone 6 is an instance of the new class obviously it is in or the new class 05:26.890 --> 05:32.320 because you created it using that class or as an instance of that class 05:35.700 --> 05:38.410 so you get true. 05:38.760 --> 05:52.450 Now if you try to check if it's an instance of the superclass which is phone six you get also true because 05:52.450 --> 05:55.630 the subclass inherits everything from the superclass. 05:55.660 --> 06:02.510 So anything you create using smartphone 6 is also going to be an instance of forensics. 06:02.530 --> 06:02.800 All right. 06:03.160 --> 06:09.970 So hopefully this gave you a good understanding of inheritance between classes in iOS 6.