Learning Object Oriented Language Features

An object-based language encapsulates attributes and behaviors in objects. To be known as an object-oriented language, the language must also support inheritance and polymorphism. This chapter introduces you to Java's language features that support these twin pillars of object orientation. Furthermore, the chapter introduces you to interfaces, Java's ultimate abstract type mechanism.

Inheritance is a hierarchical relationship between entity categories in which one category inherits attributes and behaviors from at least one other category. For example, tiger inherits from animal (tiger is a kind of animal), car inherits from vehicle (car is a kind of vehicle), and checking account inherits from bank account (checking account is a kind of bank account). Animal, vehicle, and bank account are more generic categories; and tiger, car, and checking account are more specific categories.

Java supports implementation inheritance (class extension) by providing language features for declaring and initializing classes that are extensions of existing classes. After showing you how to use these features, this section introduces you to a special class that sits at the top of Java's class hierarchy. The section then introduces you to composition, an alternative to implementation inheritance for reusing code. Lastly, I will show you how composition can overcome problems with implementation inheritance.

NOTE: Java also supports another kind of inheritance called interface inheritance. Later in this chapter, while discussing Java's interfaces language feature, I discuss interface inheritance.

Was this article helpful?

0 0

Post a comment