CIS163AA - Java Prog I - Sect 5811 - Worksheet #7 - by Pat Moss

Due Monday, November 28, 2005

Name: Pat Moss

I.  Definitions:  Please explain the following terms:

 1. inheritance   -- The ability to derive a new class from an existing
    (p. 650)         one. Inherited variables and methods of the original
                     (parent) class are available in the new (child)
                     class as if they were declared locally.

 2. override a method -- The process of modifying the definition of an
    (p. 655)             inherited method to suit the purposes of the
                         subclass. See also shadowing variables.

 3. abstract class -- A Java reserved word that serves as a modifier for
    (p. 639)          classes, interfaces, and methods. An abstract class
                      cannot be instantiated and is used to specify bodiless
                      abstract methods that are given definitions by derived
                      classes. Interfaces are inherently abstract.

 4. adaptor class  -- A class defined with empty methods corresponding to
    (p. 639, 652)     the methods invoked when particular events occur. A
                      listener can be derived from an adaptor class.

 5. AWT            -- Abstract Windowing Toolkit.
    (p. 639)          The package in the Java API (java.awt) that contains
                      the classes related to graphics and graphical user
                      interfaces. See also Swing.

 6. JTextField     -- A public class, derived from JTextComponent and
    (p. 189-193,839)  implementing SwingConstants, that represents a single
                      line area for displaying or editing text (often used
                      as an input field).

 7. Timer class    -- An object that generates an event at regular intervals.
    (p. 661, 884) 
    (inheritance p. 469-473)

 8. class hierarchy -- A tree-like structure created when classes are derived
    (p. 643)           from other classes through inheritance. See also
                       interface hierarchy.

 9. extends        -- A Java reserved word used to specify the parent class
    (p. 647)          in the definition of a child class.

II. Question or short essay

 1. What is the purpose of inheritance in Java? (p. 438)
    We can derive a new class from an existing class.
    Via inheritance, the new class automatically contains the variables and
    methods of the original class. Then, to tailor the class as needed, the
    programmer can add new variables and methods to the derived class or
    modify the inherited ones.

 2. Describe the relationship between a parent class and a child class?
    (p. 439)
    The original class that is used to derive a new one is called the
    parent class, superclass, or base class. The derived class is called
    a child class, or subclass. Java uses the reserved work extends to
    indicate that a new class is being derived from an existing class.

 3. What is the purpose of the protected modifier? (p. 657)
    A Java reserved word that serves as a visibility modifier for methods
    and variables. Protected methods and variables are inherited by all
    subclasses and are accessible from all classes in the same package.
    See also private and public.

 4. What is the purpose of the super interface? (p. 444-448)
    super -- A Java reserved word that is a reference to the parent class
    (p. 660) of the object making the reference. Often used to invoke a
             parent's constructor.

 5. What is the significance of the Object class?
    (p. 454-455, 857)
    In Java, all classes are derived ultimately from the Object class.
    If a class definition doesn't use the extends clause to derive itself
    explicitly from another class, then that class is automatically derived
    from the Object class by default.

 6. What are some important methods of the Object class that are inherited
    by all objects? (p. 454-455)
    a. All public methods of Object are inherited by every Java class.
    b. toString
    c. equals

 7. How does inheritance support software reuse?
    We may want to create a class that is, say, 95% identical to an
    existing class. So, instead of creating a new class from scratch,
    we can save time and effort my using inheritance to modify/extend
    a similar existing class.

 8. What is the effect of using final as a modifier on a method?
    (p. 457)
    Because a final method cannot be overridden in subclasses, an abstract
    final method would have no way of being given a definition in subclasses.
    
III. Programming Exercises