All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
在AJAX程序中实现互斥揭秘_[AJAX教程]
PHP实例:PHP中使用的运算符号_[PHP教程]
C#中MDI窗体概述
表示的特殊字符_JavaScript技术_编程技术
C#中如何得到主机名与IP地址_[Asp.Net教程]
关闭按钮点击事件的捕捉_[Asp.Net教程]
在Asp.net中为图像加入版权信息_[Asp.Net教程]
SQL Server得到表记录总数另类方法_[SQL Server教程]
客户端回调实现gridView无刷新分页_[Asp.Net教程]
Gridview的多种使用方法总结_[Asp.Net教程]
Reading number is top 10 pictures
BingBingFan apple dew point photo gallery2
Go to the national museum2
运动的范冰冰2
Fender Bender that so horrifying1
NeedWallpaper10
刘亦菲写真集2
Summer is most suitable for young people to travel in China9
看如何给单纯的少女洗脑
Summer is most suitable for young people to travel in China4
The little woman's bright wire3
Download software ranking
Jinling thirteen stock
电脑知识及技巧大合集
Boxer's Top ten classic battle6
Boxer's Top ten classic battle2
Ashlynn Video3
Sora aoi's film--cangkong_Blue.Sky
WebService在.NET中的实战应用教学视频 → 第1集
美女写真1
Popkart Cracked versions Mobile phone games
Unix video tutorial19
aaa published in(发表于) 2014/7/19 0:12:40 Edit(编辑)
delphi类的多态性

delphi类的多态性

delphi类的多态性

多态性

在Object Pascal 语言中定义的类的方法通常是“静态”的,也就是在编译和链接阶段就确定了对象方法的调用地址。

面向对象的程序设计语言还可以在运行时才确定对象方法的调用地址,这种调用函数的方式叫做多态性,有时也称为动态联编或滞后联编。在Object Pascal 语言中,多态性是通过虚拟方法或动态方法实现的。

通常,可以将类中的方法定义为下面的3 种方式:

• 静态方法。

• 虚拟方法。

• 动态方法。

在默认情况下定义的方法为静态方法,静态方法的调用地址在编译和链接的过程中就确定了。

在类中,如果定义了一个方法,在它的派生类中也可以定义一个同样的方法。对于静态方法,通常叫做“静态重载”。

下面的例子说明了静态方法Infor 的调用情况:

program Project1;

{$APPTYPE CONSOLE}

type

TPerson = class //人类

procedure Infor; //显示信息

end;

TEmployee = class(TPerson) //职员类

procedure Infor; //显示职员信息

end;

procedure TPerson.Infor; //显示调用的是TPerson 类的Infor

begin

Writeln ( ’TPerson.Infor’);

end;

procedure TEmployee.Infor; //显示调用的是TEmployee 类的Infor

begin

Writeln(’TEmployee.Infor’);

end;

var

P1: TPerson; //声明一个人类的变量

E1: TEmployee; //声明一个职员类的变量

begin

P1:=TPerson.Create ;

P1.Infor; //调用的是TPerson 类的Infor

P1.Destroy;

P1:=TEmployee.Create;

P1.Infor; //调用的是TPerson 类的Infor

TEmployee(P1).Infor; //调用的是TEmployee 的Infor

P1.Destroy;

E1:=TEmployee.Create;

E1.Infor; //调用的是TEmployee 类的Infor

E1.Destroy;

end.

运行结果如下:

TPerson.Infor

TPerson.Infor

TEmployee.Infor

TEmployee.Infor

可以看到,在“静态重载”的情况下,Infor 的调用是根据对象的类型来确定的。虚拟方法和动态方法也可以在派生类中被重载,通常称为“动态重载”。对象方法具体使用的并不是变量声明时指定的类的类型。



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.