7.8 Polymorphisme Challenge

Hello everyone, in this video we will make a small challenge Concerning polymorphism As we saw, in the previous video So the challenge is to create a class vehicle, car. and truck The 3 classes, will have as method "AfficheToi" The method must display for the vehicle class for example I am a vehicle. For the car class "I am a car" and for the truck class "I am a truck". The car and truck class, inherits the vehicle class. And then create the object vehicle, car, truck in the Main class Then uses the method "AfficheToi" So you are ready? Let’s go! I hope it was simple for you. We’ll make the correction together. First, we will create the vehicle class and that will have the method "AfficheToi" Public void AfficheToi and inside "I am a vehicle" We will do the same for the car class. So we’re going to create the car class and create the method "AfficheToi" Public void AfficheToi inside. "I’m a car". And the same for the truck So, we create the truck class. And inside the method class AfficheToi I am to truck The truck and car class inherits the vehicle class We add "extends" vehicle for our two classes Now the vehicle to its own "AfficheToi" and his daughters also car and truck We go into the hand class and create the objects. We will start with the vehicle class Vehicle. new vehicle v. File and we will create the car object car new Car. vo.ShowTo Finally, we will create the truck object Truck c = new truck c.ShowWe will now launch our program to check if it works. As we can see we have "I am a vehicle" "I am a car" "I am a truck" Now, if I go into the car class and delete the ShopShow method This time we will have the same message as in the vehicle, "I am a vehicle" We can relaunch our program to check. That was it for this challenge. As you can see, it was very simple. I’ll see you next time.