Return to the glossary index

A class serves as a template or guide for designing specific objects. For example, a “Car” class might contain attributes such as make, model, year, and color, as well as methods like “start” and “accelerate.”

Using this class as a reference, we can create instances of specific objects. For instance, by instantiating a “myCar” object from the “Car” class with specific characteristics such as “Tesla,” “Model S,” 2022, and “Red,” we can then call methods like “start” and “accelerate” on that object.

Thus, calling the “start” method on the “myCar” object triggers the display of a message indicating that the Tesla Model S is starting. Similarly, calling the “accelerate” method displays a message indicating that the Tesla Model S is accelerating to a given speed. On the other hand, if we tried to call a non-existent method like “brake” on this object, no action would be performed.

Return to the glossary index