Throughout this chapter, we made use of a Bicycle class. As illustrated in the following, we created a hierarchy to demonstrate inheritance as a key feature of OOP. All objects inherit from the Object class in Java. Our hierarchy has Bicycle inheriting from TwoWheeled, which inherits from Vehicle, which inherits from Object:
For our Bicycle class to work with the intended hierarchy, we created classes for Vehicle and TwoWheeled. Here are those classes:
public class Vehicle {
}
public class TwoWheeled extends Vehicle {
}
The Vehicle and TwoWheeled classes do not offer anything to the Bicycle class. Normally, each would have attributes and behaviors associated with them.
The completed Bicycle class, as refined throughout this chapter, is provided in the following sections. This first section has the class definition and the...