7.7 Polymorphisme

Hello everyone In this video, we’re going to do a little challenge on encapsulation. It is a very very simple challenge that consists in creating a car class. Private properties name, price, speed. All 3 are thongs The "Car" class must have the Setters and Getters as we saw in the previous video. In the "Main" class create a Car object Use the setters to write the name, price and speed and use the getters to display the information so read the name, price and speeds. So you’re ready? Come on, let’s go. So how was it? I hope you did it. Let’s do it together. First, we will create the car class. As private property name price And speed. all string Now, we will create the getters and setters so Alt + Insert Or else right click then choose "Generate" and then select getters and setters Now, that we have, our getters and setters. We go in "Main" class and create our object "Car". So, Comem Car variable name "v" is equal new Car Now, let’s call our setters. To write the name, price and speed So v. setNam Bob Then v. setPrix 50000 v.setVitesse 250 We will display them. So "sout" then tab and inside getNom getPrix speed v.getVitesse We launch our program to see if it works. As we can see, we do have "Bob" price and speed That’s it for this challenge As you saw, it was very simple. I’ll see you around.