Java Reference
In-Depth Information
figure 4.47
Four types of class
methods
Method
Overloading
Comments
final
Potentially inlined
Invariant over the inheritance hierarchy (method is
never redefined).
abstract
Runtime
Base class provides no implementation and is
abstract. Derived class must provide an
implementation.
static
Compile time
No controlling object.
Other
Runtime
Base class provides a default implementation that
may be either overridden by the derived classes or
accepted unchanged by the derived classes.
summary
Inheritance is a powerful feature that is an essential part of object-oriented pro-
gramming and Java. It allows us to abstract functionality into abstract base classes
and have derived classes implement and expand on that functionality. Several
types of methods can be specified in the base class, as illustrated in Figure 4.47.
The most abstract class, in which no implementation is allowed, is the
interface . The interface lists methods that must be implemented by a derived
class. The derived class must both implement all of these methods (or itself be
abstract) and specify, via the implements clause, that it is implementing the
interface. Multiple interfaces may be implemented by a class, thus providing a
simpler alternative to multiple inheritance.
Finally, inheritance allows us to easily write generic methods and classes
that work for a wide range of generic types. This will typically involve using a
significant amount of casting. Java 5 adds generic classes and methods that
hide the casting. Interfaces are also widely used for generic components, and
to implement the function object pattern.
This chapter concludes the first part of the text, which provided an over-
view of Java and object-oriented programming. We will now go on to look at
algorithms and the building blocks of problem solving.
key concepts
abstract class A class that cannot be constructed but serves to specify func-
tionality of derived classes. (129)
abstract method A method that has no meaningful definition and is thus
always defined in the derived class. (128)
 
 
Search WWH ::




Custom Search