References


Self-Test Questions

1. 

What are the three essential purposes of inheritance?

image from book

2. 

A class that belongs to an inheritance hierarchy participates in what type of relationship with its base class?

 - an is a relationship

3. 

Describe the relationship between the terms interface, class, and type.

image from book

4. 

How do you express generalization and specialization in a UML class diagram? You may draw a picture to answer the question.

 - a line with a hollow-tipped arrow extending from the derived class to the base class

5. 

Describe how to override a base class method in a derived class.

 - define a method with the same signature as the base class method.

6. 

Why would it be desirable to override a base class method in a derived class?

 - to provide a specialized implementation of that method

7. 

What’s the difference between an ordinary method and an abstract method?

image from book

8. 

How many abstract methods must a class have before it must be declared to be an abstract class?

image from book

9. 

List several differences between classes and interfaces.

image from book

10. 

How do you express an abstract class in a UML class diagram?

 - the name of the class is in italics and has the --abstract-- stereotype

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?

image from book

12. 

List the four authorized members of an interface.

 - constant fields; abstract methods; nested class declarations; nested interface declarations

13. 

What two ways can you express realization in a UML class diagram. You may use pictures to answer the question.

image from book

14. 

How do you call a base class constructor from a derived class constructor?

image from book

15. 

How do you call a base class method, other than a constructor, from a derived class method?

image from book

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.

 - refer to figure 11-18

17. 

What can you do to prevent or stop a class from being inherited?

 - use the final keyword in the class declaration

18. 

What can you do to prevent a method from being overridden in a derived class?

 - declare the method to be final

19. 

State, in your own words, a good definition for the term polymorphism.

 - treating different things in the same way

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




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net