WEBVTT

00:00.080 --> 00:00.620
Hi everyone.

00:00.620 --> 00:01.340
Welcome back.

00:01.370 --> 00:06.950
In this lecture we are going to look into the behavior of the superclass, which is the vehicle class

00:06.950 --> 00:08.990
by making it an abstract class.

00:08.990 --> 00:12.050
So what I'm going to do I'm going to add the abstract behavior here.

00:12.080 --> 00:12.680
There you go.

00:12.680 --> 00:15.050
And then I'm going to define a function named drive.

00:15.080 --> 00:21.020
So in this case let's go ahead and add public abstract string and then drive.

00:21.050 --> 00:25.940
So I'm hiring a function named drive which is common across all vehicles okay.

00:25.970 --> 00:31.130
So now as soon as you add this the car class and the truck class are going to have compilation issues

00:31.130 --> 00:33.800
because they need to implement the drive function there.

00:33.800 --> 00:37.370
So in this case let's go ahead and implement the method.

00:37.910 --> 00:38.510
There you go.

00:38.510 --> 00:42.770
So the drive function is going to return what type of vehicle it is driving.

00:42.770 --> 00:44.780
So in this case it is a car okay.

00:44.810 --> 00:47.600
We'll go ahead and do the same thing for the truck one two.

00:47.630 --> 00:50.690
So in this case let's go ahead and implement the method.

00:51.170 --> 00:53.990
And in this case we are going to return the truck.

00:55.100 --> 01:00.260
So what we are learning is that what is the effect of adding this abstract keyword to the vehicle class

01:00.260 --> 01:02.630
and the effect of the same in the subclasses.

01:02.630 --> 01:07.280
So the effect of the abstract keyword is similar to any other regular class.

01:07.280 --> 01:11.960
So if you add a class abstract and if you add an abstract function, all the classes that's extending

01:11.960 --> 01:15.140
this vehicle class need to provide an implementation.

01:15.140 --> 01:17.300
That's exactly what we did over here.

01:17.300 --> 01:22.520
So it is a common practice to provide some abstract methods in a sealed abstract class, and then have

01:22.520 --> 01:25.100
those behaviors implemented in the subclasses.

01:25.130 --> 01:27.890
Now what we will do, we'll go ahead and write some test cases.

01:27.890 --> 01:30.710
So what I'm going to do, I'm going to create the test case.

01:30.710 --> 01:32.600
I'm going to name this one as drive okay.

01:32.630 --> 01:36.290
So we already have these instance checks successfully passing.

01:36.290 --> 01:39.800
Now the next thing is we are going to check what is the drive function.

01:39.830 --> 01:41.360
Assertion returns okay.

01:41.390 --> 01:43.550
So in this case let's do assert equals.

01:43.550 --> 01:44.180
There we go.

01:44.180 --> 01:46.160
So hard drive what does it return.

01:46.190 --> 01:49.580
So in this case the car drive is going to return you a car.

01:49.610 --> 01:49.940
Right.

01:49.970 --> 01:52.160
So that's what we are actually returning over here.

01:52.160 --> 01:54.740
So if you go and take a look at it that's what it returns.

01:54.740 --> 01:56.720
Let's copy this and then put this over here.

01:56.720 --> 02:01.400
And then similarly for the truck to drive what does it return.

02:01.400 --> 02:03.980
So the truck dot drive return the truck.

02:04.010 --> 02:04.460
Right.

02:04.490 --> 02:06.980
Let's copy this and then put it over here.

02:07.010 --> 02:07.610
There you go.

02:07.640 --> 02:09.680
Now let's go ahead and execute this test case.

02:09.680 --> 02:13.040
So this test case should succeed without any issues.

02:14.660 --> 02:15.260
There you go.

02:15.260 --> 02:17.000
The test case gave us a green check.

02:17.030 --> 02:19.220
That means it is working as expected.

02:19.220 --> 02:24.860
So basically what I wanted to show you is that by making the Seal class abstract, the behavior of the

02:24.860 --> 02:30.920
abstract class is going to be very similar to applying the abstract class of a regular class.

02:30.920 --> 02:32.570
I hope the explanation is clear.

02:32.570 --> 02:35.750
I do understand this is a very naive and simple example.

02:35.750 --> 02:40.790
As I mentioned, there is a dedicated section where we are going to implement a real time example.

02:41.120 --> 02:46.460
I just wanted to keep this examples really simple and naive, so that it is pretty easy to grasp these

02:46.460 --> 02:50.150
concepts that you can use to implement a real time example.

02:50.150 --> 02:51.620
Well, this marks the end of this lecture.

02:51.620 --> 02:52.760
Thank you for watching.
