5.1 Concepts of Object-Oriented Languages 157
way, the (semantic) meaning of a method can be specified in greater detail. Often,
the class also defines the methods; but these definitions can possibly be overloaded.
Objects that have further members beside the required ones can possibly belong to
that class as well.
The object class is the concept for data abstraction provided by object-oriented
languages. It serves as a generator for objects, which are its instances.
5.1.3 Inheritance
The term inheritance refers to the incorporation of all members of a class B into a
new class A.ClassA can additionally define members and overwrite methods of B.
If A inherits from B, then A is called a derived class,orsubclass,ofB; B is called
the base class,oralsosuperclass ,ofA.
Inheritance significantly simplifies to create extensions and variations of classes.
Through the organization in inheritance hierarchies, class libraries can be structured
by providing different layers of abstraction.
The concept of inheritance allows us, in a simple way, to reuse parts of an ex-
isting implementation, to extend it and, if needed, to locally adjust it to specific re-
quirements or conditions by modifying individual methods. Often, it is also possible
to define abstract classes. Abstract classes are classes with methods that are not yet
implemented. Abstract classes do not have instances, that is, objects of such a class
must belong to concrete subclasses. This introduces a similar flexibility as in natural
languages through abstract terms and different abstraction levels. Whatever can be
formulated at a higher abstraction level, has a wider degree of applicability and, thus,
a higher amount of reusability.
Typed object-oriented languages support inheritance hierarchies. If a class A in-
herits from class B, then the type attached to A is a subtype of the type of B. Each
object of a subtype is automatically also an element of the supertype; a derived class
becomes a subclass of the parent class. This results in the option that objects of any
subtype of the specified type can appear when used as inputs (function parameter,
right-hand sides of assignments) or as return values of methods. We call this the
subtyping rule.
A restriction of this useful principle, however, must be mentioned: objects of a
subclass of B may possibly contain additional members and, thus, cannot necessarily
bestoredwithinthesamespaceasreservedfor B objects.Thisisofcoursedifferentif
theprogramminglanguagedoesnotdeal withobjectsthemselves,butwithreferences
to objects only, such as the programming languages E
IFFEL and JAVA: references
always require the same amount of memory – independent of the class of the objects
they point to. In contrast, the programming language C++ differentiates between
objects and references to objects. Thus, in C++, for a parameter whose type is a
class A,thecopy constructor A
(const A& x) of class A is implicitly called. This
constructor should apply an adequate type cast to every object of a subclass of A.
We call the objects of A that are not also objects of a proper subclass the proper
objects of A. Accordingly, we call A the proper type of the proper A objects. Each