Originale-mail to me for new edition

 

Inherited

 

The reserved word inherited plays a special role in implementing polymorphic behavior. It can occur in method definitions, with or without an identifier after it.

If inherited is followed by the name of a member, it represents a normal method call or reference to a property or field except that the search for the referenced member begins with the immediate ancestor of the enclosing method’s class. For example, when

inherited Create(...);

occurs in the definition of a method, it calls the inherited Create.

When inherited has no identifier after it, it refers to the inherited method with the same name as the enclosing method. In this case, inherited takes no explicit parameters, but passes to the inherited method the same parameters with which the enclosing method was called. For example,

inherited;

occurs frequently in the implementation of constructors. It calls the inherited constructor with the same parameters that were passed to the descendant.

 

Topic groups

 

See also

Method declarations and implementations

Methods: Overview

 

 

译文

 

继承

 

保留字inherited在实现多种行为中扮演特殊的角色。它可以出现在方法定义中,在其后面可以有或没有标识符。

如果inherited之后跟随一个成名名称,那么除了表示在封装了方法的类的直接祖先中搜寻成员之外,还可以表示标准的方法调用或者对属性或域的引用。例如,当如下语句

inherited Create(...);

出现在方法的定义声明中时,表示对继承得到的Create方法的调用。

当没有标识符跟随在inherited之后时,它表示对当前定义声明封装的方法在所属类的直接祖先中同名方法的调用。这时,保留字inherited不必显示地接受任何参数,但实际上传递到继承的方法中的参数与当前封装的方法调用的参数是相同的(如果有参数)。例如,如下语句

inherited;

经常出现在构造器的实现中。它调用继承得到的构造器并且接受的参数(如果有)与传递到后裔类中构造器的参数相同。

 

主题组

 

相关主题

方法声明和实现

方法:概述