Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 266
Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 266
Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 266
Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 266
10.2.1 多态的概念
什么是多态?
“多态”一词最早用于生物学,指同一种族的生物体具有相同的特性。比如青蛙小的时候是蝌蚪,长大了就是青蛙,同是一种生物但是有不同的表现形式。
在C#中,多态性的定义是:同一操作作用于不同的类的对象,不同的类的对象进行不同的执行,最后产生不同的执行结果。如所有的动物都有吃东西这个功能,而狼吃肉、羊吃草,每种动物都有自己吃东西的方式。在【范例10-2】中的Person类中定义了两个同名的构造函数,但是参数个数不同,这种情况叫做重载,重载是多态的一种。
Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 276
Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 276
Warning: Undefined array key 0 in /www/wwwroot/w/show/success.php on line 276
Warning: Trying to access array offset on value of type null in /www/wwwroot/w/show/success.php on line 276