zoukankan      html  css  js  c++  java
  • inherited使用举例

    Iherited 是一个保留字,在用在子类的(Method)的实现区里,当要设定子类某个方法的
     实现内容,但这个方法实现区所包含的代码只会比父类所定义的实现内容多出一些代码,
     而原本的部分仍然要延用时,就可以在类方法的实现区中用 Iherited 这个保留字
     后面加上父类的成员函数的标识符(Identifier)  ,并且给予适当参数.
     而且,Iherited并非只能在override 的方法实现里,而且在子类设定的任何方法里使用
     而且能调用父类任何成员函数.
     1unit Unit1;
     2
     3interface
     4
     5uses
     6  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     7  Dialogs, StdCtrls;
     8type
     9  TPerson = class(TObject)
    10  public
    11  CONSTRUCTOR  Create;
    12  FUNCTION Swim:String;
    13    { Public declarations }
    14  end;
    15type
    16  TET = class(TPerson)
    17  public
    18  Name: String;
    19  PROCEDURE  Swim;
    20  PROCEDURE  Swum; 
    21    { Public declarations }
    22  end;
    23type
    24  TForm1 = class(TForm)
    25    Button1: TButton;
    26    procedure Button1Click(Sender: TObject);
    27  private
    28    { Private declarations }
    29  public
    30    { Public declarations }
    31  end;
    32
    33var
    34  Form1: TForm1;
    35
    36implementation
    37
    38PROCEDURE  TET.Swum;
    39BEGIN
    40  ShowMessage('根据之前的资料 ' + #13+ #13 + '刚才');// + inherited Swim);
    41
    42end;
    43
    44PROCEDURE  TET.Swim;
    45BEGIN
    46 ShowMessage(Self.ClassName + '的 Create'+ #13+ #13);//  + inherited Swim);
    47
    48end;
    49
    50FUNCTION TPerson.Swim:STRING;
    51BEGIN
    52  result := '你游' + InputBox(Self.ClassName + '游泳池问卷','你游什么方式','蛙游'+ '啊!';
    53ShowMessage('问卷填好了!');
    54end;
    55
    56CONSTRUCTOR  TPerson.Create;
    57BEGIN
    58  INHERITED ;
    59  ShowMessage('执行 ' + Self.ClassName + '的 Create'+ #13+ #13 +'欢迎光临Fish游泳池');
    60end;
    61
    62{$R *.dfm}
    63
    64procedure TForm1.Button1Click(Sender: TObject);
    65 VAR
    66  aPerson: TPerson;
    67  theEt: Tet;
    68begin
    69  aPerson := TPerson.Create;
    70  aPerson.Swim;
    71  aPerson.Free;
    72  theEt := TET.Create;
    73  theEt.Name := '外星人ET';
    74  theEt.Swim;
    75  theEt.Swum;
    76  theEt.Free;
    77end;
    78
    79end.
    80
    81
  • 相关阅读:
    7. 流程控制
    6. 工作区域与包
    5. Go函数
    4. Go常量
    面试题1
    数据库三范式
    触发器和存储过程
    面试题
    js 程序执行与顺序实现详解 ,来自网上
    基础的优化数据库查询,个人笔记
  • 原文地址:https://www.cnblogs.com/dreamszx/p/1572007.html
Copyright © 2011-2022 走看看