Classes


Premium Content - Free Preview

Cars in the real world are rarely custom-made. Instead a blueprint is created for a specific car, such as the Toyota Camry, and then thousands of cars can be created based on it. Each Camry consists of the same components, but can have different details "filled-in". For example, one car might be blue and have a sunroof, while another car might be black and have leather seats.

toyota-car-factory

Similarly, when programming, you do not need to custom-code each object on its own. Instead, you can create Classes as a "blueprint" for each object. In a racing game you can create a Class Racecar and then create different instances of cars within the game. (Each instance of the Class Car is also known as a Car Object.) So player1 and player2 can each have their own instance of Racecar which might be called racecar1 and racecar2. While each car will have the same overall structure and components, they can have different values for their variables, for example:


End of Free Content Preview. Please Sign in or Sign up to buy premium content.

Comments

Contact Us
Sign in or email us at [email protected]