An Overview of Inheritance

You extend a class by creating a new class. The former and the latter will then have a parent-child relationship. The original class is the parent class or the base class or the superclass. The new class is called a child class or a subclass or a derived class of the parent class. The process of extending a class in object-oriented programming is called inheritance. In a subclass you can add new methods and new fields as well as override existing methods in the parent class to change their behaviors.

Note that LZX does not support method overloading, a feature in Java, C#, and many other OOP languages. Method overloading allows you to have multiple methods with the same name in the same class.

Figure 12.1 shows the UML class diagram that depicts a parent-child relationship between a class and its child class.

Figure 12.1. The UML class diagram for a parent class and a child class


Note that a line with an arrow like that in Figure 12.1 is used to depict generalization, e.g. the parent-child relationship.

The benefits of inheritance are obvious. Inheritance gives you the opportunity to add some functionality that does not exist in the original class. It also gives you the chance to change the behaviors of the existing class to better suit your needs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset