zoukankan      html  css  js  c++  java
  • 关于类的入门的例子(5): override

    unit Unit1;
    
    interface
    
    uses
      Classes, Controls, Forms, Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      end;
    
      TBase = class
        procedure proc1; virtual;
        procedure proc2;
      end;
    
      TChild = class(TBase)
        procedure proc1; override;
        procedure proc2;
      end;
    
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    { TBase }
    
    procedure TBase.proc1;
    begin
      ShowMessage('B1');
    end;
    
    procedure TBase.proc2;
    begin
      ShowMessage('B2');
    end;
    
    { TChild }
    
    procedure TChild.proc1;
    begin
      //inherited;
      ShowMessage('C1');
    end;
    
    procedure TChild.proc2;
    begin
      ShowMessage('C2');
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      B: TBase;
      C: TChild;
      BC: TBase;
    begin
      B := TBase.Create;
      C := TChild.Create;
      BC := TChild.Create;
    
      B.proc1;          //B1
      B.proc2;          //B2
      TChild(B).proc1;  //B1
      TChild(B).proc2;  //C2
    
      C.proc1;          //C1
      C.proc2;          //C2
      TBase(C).proc1;   //C1
      TBase(C).proc2;   //B2
    
      BC.proc1;         //C1
      BC.proc2;         //B2
      TBase(BC).proc1;  //C1
      TBase(BC).proc2;  //B2
      TChild(BC).proc1; //C1
      TChild(BC).proc2; //C2
    
      B.Free;
      C.Free;
      BC.Free;
    end;
    
    end.
    
  • 相关阅读:
    浅谈线段树
    浅谈KMP
    20200729线上模拟题解
    20200727线上模拟题解
    声明
    tarjan--割点,缩点
    20201029模拟
    高精模板
    二分图--二分图的几种模型
    树的直径与树的重心
  • 原文地址:https://www.cnblogs.com/del/p/1002959.html
Copyright © 2011-2022 走看看