Monthly Archives: June 2022

Relationships: is-a and has-a The inheritance relationship between a subclass and its superclass is embodied by the is-a relationship. Since a subclass inherits from its superclass, a subclass object is-a superclass object, and can be used wherever an object of the superclass can be used. It has particular consequences for how objects can be used. An object of the TubeLight class is-an object of the superclass Light. Referring to Figure 5.1, an object of the TubeLight class can be used wherever an object of the superclass Light can be used. The inheritance relationship is transitive: If class B extends class A and class C extends class B, then class C will also inherit from class A via class B. In Figure 5.1, an object of the SpotLightBulb class is-an object of the class Light. The is-a relationship does not hold between peer classes: An object of the LightBulb class is…

Read more

1/1