10.11. Programming Exercises

 
[Page 341]

Chapter 10. Abstract Classes and Interfaces

Mayan God Shel, Mexico. Photographer: Philip Coblentz. Courtesy Brand X Pictures.

Objectives

  • To design and use abstract classes ( §10.2).

  • To process a calendar using the Calendar and GregorianCalendar classes ( §10.3).

  • To declare interfaces to model weak inheritance relationships ( §10.4).

  • To define a natural order using the Comparable interface ( §10.4.1).

  • To know the similarities and differences between an abstract class and an interface ( §10.4.2).

  • To declare custom interfaces ( §10.4.3).

  • (Optional) To make objects cloneable using the Cloneable interface ( §10.4.4).

  • To use wrapper classes ( Byte , Short , Integer , Long , Float , Double , Character , and Boolean ) to wrap primitive data values into objects ( §10.5).

  • (Optional) To use the BigInteger and BigDecimal classes for computing very large numbers with arbitrary precisions ( §10.5.6).

  • To create a generic sort method ( §10.5).

  • To simplify programming using JDK 1.5 automatic conversion between primitive types and wrapper class types ( §10.6).

  • (Optional GUI) To handle GUI events ( §10.7).


[Page 342]

10.1. Introduction

In the inheritance hierarchy, classes become more specific and concrete with each new subclass . If you move from a subclass back up to a superclass, the classes become more general and less specific. Class design should ensure that a superclass contains common features of its subclasses. Sometimes a superclass is so abstract that it cannot have any specific instances. Such a class is referred to as an abstract class .

Sometimes it is necessary to derive a subclass from several classes. This capability is known as multiple inheritance . Java, however, does not allow multiple inheritance. A Java class may inherit directly from only one superclass. This restriction is known as single inheritance . If you use the extends keyword to define a subclass, it allows only one parent class. With interfaces, you can obtain the effect of multiple inheritance.

This chapter introduces abstract classes and interfaces, and discusses how to use wrapper classes for primitive data type values.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

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