Page 541 - Introduction to Programming with Java: A Problem Solving Approach
P. 541
Review Question Solutions 507
8. Nothing. This happens automatically. You can, however, preempt this by writing super(); as the first
line in your derived constructor.
9. False. There is no problem. The JVM selects the method in the subclass.
10. Yes. In the call statement, preface the common method name with super.
11. No. If a superclass’s instance variable is private, you cannot access it directly from a subclass. You can access it by calling an accessor method (assuming the accessor is public). In calling the superclass’s method, there’s no need to prefix the method call with a reference dot.
12. False. The super. prefix is only necessary when you want to call a superclass method that has been overridden.
13. False. A final method is allowed to contain regular variables. It’s called “final” because it’s illegal to create an overriding version of the method in a subclass.
14. False. Composition and inheritance are completely different class relationships. Composition is when a class is comprised of non-trivial constituent parts and the parts are defined to be classes. Inheritance is when one class is a more detailed version of another class. More formally, inheritance is when one class, a subclass, inherits variables and methods from another class, a superclass.
15. Because with this example, there’s a second class that is also a group of cards. Since there are two classes that share some of the same properties, you should put those common properties in a shared superclass, GroupOfCards. Doing this promotes software reuse and avoids code redundancy.
16. You can make a complicated association easier to recognize and understand by organizing the references to all association participants and other association information and methods in a single class that represents the association only. Apago PDF Enhancer