国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 河北区| 库伦旗| 探索| 丹巴县| 武平县| 广宗县| 吉水县| 昆山市| 郸城县| 思茅市| 潞西市| 都江堰市| 北票市| 唐海县| 永宁县| 治县。| 长沙县| 视频| 德阳市| 石河子市| 山丹县| 平塘县| 鄂托克前旗| 龙胜| 双辽市| 丰原市| 奉新县| 普格县| 高安市| 赞皇县| 六盘水市| 双鸭山市| 余干县| 孟津县| 鄢陵县| 郑州市| 莱州市| 沙坪坝区| 兴业县| 黔江区| 上犹县|