1. | What are the three essential purposes of inheritance? |
|
2. | A class that belongs to an inheritance hierarchy participates in what type of relationship with its base class? |
|
3. | Describe the relationship between the terms interface, class, and type. |
|
4. | How do you express generalization and specialization in a UML class diagram? You may draw a picture to answer the question. |
|
5. | Describe how to override a base class method in a derived class. |
|
6. | Why would it be desirable to override a base class method in a derived class? |
|
7. | What’s the difference between an ordinary method and an abstract method? |
|
8. | How many abstract methods must a class have before it must be declared to be an abstract class? |
|
9. | List several differences between classes and interfaces. |
|
10. | How do you express an abstract class in a UML class diagram? |
|
11. | Hi, I’m a class that declares a set of interface methods but fails to provide an implementation for the those methods. What type of class am I? |
|
12. | List the four authorized members of an interface. |
|
13. | What two ways can you express realization in a UML class diagram. You may use pictures to answer the question. |
|
14. | How do you call a base class constructor from a derived class constructor? |
|
15. | How do you call a base class method, other than a constructor, from a derived class method? |
|
16. | Describe the effects using the access modifiers public, package, private, and the default access package, has on classes belonging to the same and different packages. State the effects from the both the horizontal and vertical member access perspectives. |
|
17. | What can you do to prevent or stop a class from being inherited? |
|
18. | What can you do to prevent a method from being overridden in a derived class? |
|
19. | State, in your own words, a good definition for the term polymorphism. |
|
Answers
1. | - as a way to reason about program behavior; as a way to incrementally build program functionality; as a way to gain a measure of reuse within your program |
2. | - an “is a” relationship |
3. | - an interface introduces a new data type and the set of authorized operations (methods) that can be called on that type; a class introduces a new data type and specifies behavior for one or more of its methods; the term type refers to that set of methods a particular object supports |
4. | - a line with a hollow-tipped arrow extending from the derived class to the base class |
5. | - define a method with the same signature as the base class method. |
6. | - To provide a specialized implementation of that method |
7. | - An ordinary method has a method body; an abstract method is declared to be abstract and does not have a method body. |
8. | - one |
9. | - A class can extend from only one other class but implement one or more interfaces; an interface can extend from as many interfaces as required; an interface can have no method implementations |
10. | - The name of the class is in italics and has the <<abstract>> stereotype |
11. | - abstract class |
12. | - constant fields; abstract methods; nested class declarations; nested interface declarations |
13. | - simple form (lollipop diagram) or expanded form (ordinary class diagram with hollow-arrow-tipped dotted line showing realization) |
14. | - super() |
15. | - super.methodName() |
16. | - refer to figure 11-18 |
17. | - use the final keyword in the class declaration |
18. | - declare the method to be final |
19. | - treating different things in the same way |