Java Reference
In-Depth Information
When inheriting a complete implementation, we can choose to add or override methods.
When no or only partial implementation of a type is inherited, the subclass must provide the
implementation before it can be instantiated.
Some other object-oriented languages also provide mechanisms to inherit code without inherit-
ing the type. Java does not provide such a construct.
In this chapter, we have discussed the fundamental structure of computer simulations. We have
then used this example to introduce abstract classes and interfaces as constructs that allow us to
create further abstractions and develop more-flexible applications.
Abstract classes are classes that are not intended to have any instances. Their purpose is to
serve as superclasses to other classes. Abstract classes may have both abstract methods—
methods that have a header but no body—and full method implementations. Concrete sub-
classes of abstract classes must override abstract methods to provide the missing method
Another construct for defining types in Java is the interface. Java interfaces are similar to com-
pletely abstract classes: they define method headers but provide no implementation. Interfaces
define types that can be used for variables.
Interfaces can be used to provide a specification for a class (or part of an application) without
stating anything about the concrete implementation.
Java allows multiple inheritance of interfaces (which it calls “implements” relationships) but
only single inheritance for classes (“extends” relationships).
Terms introduced in this chapter
abstract method, abstract class, concrete class, abstract subclass, multiple
inheritance, interface (Java construct), implements
Concept summary
abstract method An abstract method definition consists of a method header without a
method body. It is marked with the keyword abstract .
abstract class An abstract class is a class that is not intended for creating instances. Its
purpose is to serve as a superclass for other classes. Abstract classes may contain abstract
abstract subclass For a subclass of an abstract class to become concrete, it must
provide implementations for all inherited abstract methods. Otherwise, it will itself be
Search WWH ::

Custom Search