zoukankan      html  css  js  c++  java
  • 覆盖、再覆盖


    在实践中真的会发现更多问题.

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
    
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      end;
    
      IA = Interface
        function GetName: string;
        property Name: string read GetName;
      end;
    
      TC1 = class(TInterfacedObject, IA)
        function GetName: string; virtual;
      end;
    
      TC2 = class(TC1)
        function GetName: string; override; //覆盖
      end;
    
      TC3 = class(TC2)
        function GetName: string; override; //再覆盖
      end;
    
      TC4 = class(TC3)
        function GetName: string; override; //再覆盖
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    { TC1 }
    
    function TC1.GetName: string;
    begin
      Result := 'C1';
    end;
    
    { TC2 }
    
    function TC2.GetName: string;
    begin
      Result := 'C2';
    end;
    
    { TC3 }
    
    function TC3.GetName: string;
    begin
      Result := 'C3';
    end;
    
    { TC4 }
    
    function TC4.GetName: string;
    begin
      Result := inherited + '0';
    end;
    
    
    {测试}
    procedure TForm1.FormCreate(Sender: TObject);
    var
      v1,v2,v3,v4: IA;
    begin
      v1 := TC1.Create;
      v2 := TC2.Create;
      v3 := TC3.Create;
      v4 := TC4.Create;
      ShowMessageFmt('%s, %s, %s, %s', [v1.Name, v2.Name, v3.Name, v4.Name]); //C1, C2, C3, C30
    end;
    
    end.
    

  • 相关阅读:
    [bzoj4893]项链分赃
    [Spoj]Counting Divisors (cube)
    [Noi2016]国王饮水记
    [Noi2016]网格
    [Noi2016]优秀的拆分
    [Noi2016]区间
    [Noi2015]寿司晚宴
    Codeforces Round #411 (Div. 2)
    VK-Cup2017 Wild Card Round 2
    [Noi2015]小园丁和老司机
  • 原文地址:https://www.cnblogs.com/del/p/2311372.html
Copyright © 2011-2022 走看看