Chapter 8

   

Java™ 2 Primer Plus
By Steven Haines, Steve Potts

Table of Contents
Appendix C.  Answers to Review Questions


A1:

No, all interfaces and their methods are both public and abstract by design.

A2:

No, all methods are abstract.

A3:

You implement an interface by using the implements keyword in your class definition and then providing implementations for each method in the interface.

A4:

Multiple inheritance is the act of deriving a class from more than one class (note that Java does not support multiple inheritance).

A5:

If a class is derived from two classes and those are derived from the same class (this is called diamond inheritance) then there is a question of how the object is created in memory; there must be two instances of the same class in memory that are both references as the parent of the sub class. If the two (or more) classes that the class in question extends provide different implementations of the same method, the compiler will not know which one to reference when it is called.

A6:

If the functionality is specific to an object, then it is best to put it in the class itself.

A7:

Put methods in an interface when the functionality is external to the core functionality of objects that will implement it. Put methods in an abstract class that represent functionality that will be core to the classes that will derive from the abstract base class.

A8:

Diamond inheritance can be a result of multiple inheritance and it is deriving a class from two or more classes that are themselves derived from a common base class. The danger of this is defined in the answer to question number 5 of this chapter.


       
    Top
     



    Java 2 Primer Plus
    Java 2 Primer Plus
    ISBN: 0672324156
    EAN: 2147483647
    Year: 2001
    Pages: 332

    Similar book on Amazon

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