国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

【轉(zhuǎn)載】#335

2019-11-17 03:18:27
字體:
供稿:網(wǎng)友

【轉(zhuǎn)載】#335 - accessing a Derived Class Using a Base Class Variable

You can use a variable whose type is a base class to reference instances of a derived class.

However, using the variable whose type is the base class, you can use it to access only members of the base class and not members of the derived class.

In the example below, we have two instances of the Terrier class, which derives from Dog. One instance is referenced by a variable of type Terrier. Using this variable, you have access to all members of the Terrier class. On the other hand, the variable whose type is Dog can only reference members of the Dog class, even though the reference points to an instance of a Terrier.

1 Terrier bubba = new Terrier("Bubba", 2, "Happy");2 bubba.Growl();         // Can call Terrier.Growl3 4 Dog jack = new Terrier("Jack", 17, "Surly");5 jack.Growl();             // ERROR: Can't call Growl method

原文地址:#335 - Accessing a Derived Class Using a Base Class Variable


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 利辛县| 峡江县| 安龙县| 博湖县| 沅陵县| 怀安县| 孝感市| 肥东县| 平邑县| 合川市| 杭锦后旗| 呼图壁县| 竹山县| 临沧市| 怀柔区| 西乌珠穆沁旗| 东宁县| 利辛县| 闵行区| 琼结县| 衡阳市| 乡宁县| 岳池县| 高淳县| 兰考县| 酉阳| 建德市| 孟连| 达拉特旗| 句容市| 遂宁市| 景谷| 子长县| 静宁县| 兰坪| 乐清市| 云龙县| 闵行区| 丽水市| 宣化县| 天门市|