Navigation  without Java Scripts

Derived Classes and Inheritance

A class can be derived from another class(es), which is called a base (parent) class(es).

The class class_name is called a derived class if any base class is specified in the base class list of the class declaration or of the class implementation. A derived class inherits domains, facts, and predicates from the specified base classes.

Base classes specified in the base class list of a class declaration must not be duplicated in the base class list of the class implementation.

An abstract class cannot be specified in the class implementation's base class list.

When you declare a derived class (for example, D1 or D2), you list the base classes (for example, P1, P2, P3, and P4) in a comma-delimited base class list:

class D1 : P1, P2
or
implement D2 : P3, P4
When the base classes P1 and P2 are specified in the class D1 declaration, then the derived class D1 inherits from the base classes P1 and P2 all public domains, facts, and predicates. The inherited facts and predicates become public members of class D1 and they can be referenced as members of class D1. On the other hand, the derived class D1 inherits only possibility to use public domains inherited from the base classes; such domains cannot be qualified with the name of D1.

The derived class D1 also inherits from the base classes P1 and P2 protected domains, facts, and predicates, which are declared directly in the base classes P1 and P2.

When the base classes P3 and P4 are specified in the class D2 implementation, then the derived class D2 inherits from the base classes P3 and P4 all public domains, facts, predicates and that protected domains, facts, and predicates, which are declared directly in the base classes P3 and P4. All inherited names become private (local) to D2 and can be used only inside the implementation.

The inherited domains, predicates or facts can be redefined in the derived class. Global predicates also can be redefined inside a class, for example, the build-in global predicates beep, concat, etc. can be overridden inside a class.

Members of a base class redefined in a derived class can be accessed from the derived class with explicit qualifying a member name by the base class name. Using syntax like this:

[object_identifier :][base_class_name ::] member_name[(arguments)]
See also