- Objects
- Classes
- Inheritance
-
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
- Scope
- Inheritance
-
BlueJ Review - Class Code
- Simple Debugging
- Interactive Picture
- Refactoring Code with Inheritance
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.
End of Free Content Preview. Please Sign in or Sign up to buy premium content.
Comments
Stanley Mwangi
Jun 27, 5:19 AMThis is such a cool concept!
Bolke
Jul 13, 7:15 PMI relied on my thorough Real World knowledge to answer this one.