Inheritance

Mechanical pencils have a few of the same attributes as wooden pencils. A class definition describing a mechanical pencil therefore is very similar to that for a wooden pencil. The following class definition shows a simple example.

Image

It would be nice if the $writeColor and $eraserPercentage attributes and the erase() method declaration could be shared since they are identical between the two types of pencils. This is done through inheritance.

Inheritance is one way that relationships are built between objects. A good deal of time in the creation of any object-oriented application is spent deciding what objects need to exist and their ...

Get Oracle Database Ajax & PHP Web Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.