Programming in Java on Your Computer
- Classes and Objects in BlueJ
- Trying out Code in BlueJ
- The Code for Creating and Using Objects
- Source Code and Methods
- Accessors and Mutators
- Constructor Code
- Class Code
- Simple Debugging
- Interactive Picture
- Refactoring Code with Inheritance
Premium Content - Free Preview
In the last node, you saw how different car instances can be created from one Car Class without having to re-write any code. But what if you wanted to create another car that was similar but needed a modified template? For example, you might want to create some of the following:
- 2 different racecars, like a Formula 1 Racecar and a Rocket Car.
- Consumer cars, like the Toyota Camry and a the Ford Explorer.
- Other vehicles, like Trucks and Motorcycles.
Each type of vehicle will overlap in many ways, but also have different types of state and actions. For example, a Motorcycle can do a wheelie, while a truck can attach another cart behind it. Since each instance of a Class follows the same template, these different vehicles cannot belong to the same class. Another approach is needed.