Page 535 - Introduction to Programming with Java: A Problem Solving Approach
P. 535
• To minimize descriptive duplication, organize your ideas so that only the concepts at the very bottom of an inheritance hierarchy (the leaves of the upside-down tree) are specific enough to represent real objects.
• To enable class B to inherit all the variables and methods in class A and all of class A’s ancestors, ap- pendextends AtotheendofclassB’sheading.
• A constructor should initialize the variables it inherits by immediately calling its superclass’s construc- tor with the statement: super(<arguments>);
• You can override an inherited method by writing a different version of the inherited method in the de- rived class. Overriding occurs automatically if you use the same method name and the same sequence of parameter types, but if you do this, you must also use the same return type.
• You can access an overridden method by prefixing the common method name with super and then a dot.
• A final access modifier on a method keeps that method from being overridden. A final access modifier on a class keeps that class from being extended.
• Programmers frequently use combinations of aggregation, composition, and inheritance to deal with different aspects of an overall programming problem. In a UML class diagram, both relationships are represented by solid lines between related classes, and these lines are called associations. In a composition/ aggregation association, there is a solid/hollow diamond at the container end of each association line. In a hierarchical association, there is a hollow arrowhead at the superclass end of the association line.
• Inheritance allows you to re-use code that was written for another context.
• When you have a complicated association among objects, it may help to gather references to those ob-
jects together into a common association class.
Apago PDF Enhancer
Review Questions
§12.2 Composition and Aggregation
1. In a UML diagram, what does an asterisk (*) indicate? 2. In a UML diagram, what does a solid diamond indicate?
§12.3 Inheritance Overview
3. Explain how using an inheritance hierarchy can lead to code reusability.
4. What are two synonyms for a superclass? 5. What are two synonyms for a subclass?
§12.4 Implementation of Person/Employee/FullTime Hierarchy
6. How do you tell the compiler that a particular class is derived from another class?
7. Based on the UML diagram in Figure 12.9, an instance of the PartTime class includes the following
instance variables: name and id. (T / F)
§12.5 Constructors in a Subclass
8. In a subclass’s constructor, what do you have to do if you want to begin the constructor with a call to the
superclass’s zero-parameter constructor?
§12.6 Method Overriding
9. If a superclass and a subclass define methods having the same name and the same sequence of parameter
types, and an object of the subclass calls the method without specifying which version, Java generates a runtime error. (T / F).
Review Questions 501