You are on page 1of 4

Material 15

Inheritance
If D is a subclass of C, then D can inherit
from C, or acquire attributes (instance
variables and methods, including
constructors) from it.
In this case we may refer to C as the base
class and D as the derived class.
In some languages, we say D extends C
Inheritance supports code reuse

Single Inheritance
Single inheritance limits a class to having
only one superclass.
Single inheritance produces a class
hierarchy that can be represented as a
tree, with a single root. (Object, in Java)

Multiple Inheritance
A class may have multiple superclasses.
Inheritance from more that one parent has
good features and bad.
Good: facilitates code reuse by borrowing
characteristics from several parent classes
Bad: confusing. For example, what if two
parent classes have a method with the same
name, but different definitions?

You might also like