Hi everyone.
Welcome back.
In this lecture we are going to look into the behavior of the superclass, which is the vehicle class
by making it an abstract class.
So what I'm going to do I'm going to add the abstract behavior here.
There you go.
And then I'm going to define a function named drive.
So in this case let's go ahead and add public abstract string and then drive.
So I'm hiring a function named drive which is common across all vehicles okay.
So now as soon as you add this the car class and the truck class are going to have compilation issues
because they need to implement the drive function there.
So in this case let's go ahead and implement the method.
There you go.
So the drive function is going to return what type of vehicle it is driving.
So in this case it is a car okay.
We'll go ahead and do the same thing for the truck one two.
So in this case let's go ahead and implement the method.
And in this case we are going to return the truck.
So what we are learning is that what is the effect of adding this abstract keyword to the vehicle class
and the effect of the same in the subclasses.
So the effect of the abstract keyword is similar to any other regular class.
So if you add a class abstract and if you add an abstract function, all the classes that's extending
this vehicle class need to provide an implementation.
That's exactly what we did over here.
So it is a common practice to provide some abstract methods in a sealed abstract class, and then have
those behaviors implemented in the subclasses.
Now what we will do, we'll go ahead and write some test cases.
So what I'm going to do, I'm going to create the test case.
I'm going to name this one as drive okay.
So we already have these instance checks successfully passing.
Now the next thing is we are going to check what is the drive function.
Assertion returns okay.
So in this case let's do assert equals.
There we go.
So hard drive what does it return.
So in this case the car drive is going to return you a car.
Right.
So that's what we are actually returning over here.
So if you go and take a look at it that's what it returns.
Let's copy this and then put this over here.
And then similarly for the truck to drive what does it return.
So the truck dot drive return the truck.
Right.
Let's copy this and then put it over here.
There you go.
Now let's go ahead and execute this test case.
So this test case should succeed without any issues.
There you go.
The test case gave us a green check.
That means it is working as expected.
So basically what I wanted to show you is that by making the Seal class abstract, the behavior of the
abstract class is going to be very similar to applying the abstract class of a regular class.
I hope the explanation is clear.
I do understand this is a very naive and simple example.
As I mentioned, there is a dedicated section where we are going to implement a real time example.
I just wanted to keep this examples really simple and naive, so that it is pretty easy to grasp these
concepts that you can use to implement a real time example.
Well, this marks the end of this lecture.
Thank you for watching.