Programming Previous page   Next Page

Building on Other Classes

A MATLAB object can inherit properties and behavior from another MATLAB object. When one object (the child) inherits from another (the parent), the child object includes all the fields of the parent object and can call the parent's methods. The parent methods can access those fields that a child object inherited from the parent class, but not fields new to the child class.

Inheritance is a key feature of object-oriented programming. It makes it easy to reuse code by allowing child objects to take advantage of code that exists for parent objects. Inheritance enables a child object to behave exactly like a parent object, which facilitates the development of related classes that behave similarly, but are implemented differently.

There are two kinds of inheritance:

This section also discusses a related topic, aggregation. Aggregation allows one object to contain another object as one of its fields.


Previous page  Listing Class Methods Simple Inheritance Next page

© 1994-2005 The MathWorks, Inc.