版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Prepared byN.Sathish KumarCSE/ LecturerSKRECCOMPOSITE OBJECT RUNTIMEPOLYMORPHISM Inhentance results m a "composite obj ect at run-time. Public methods are combined into one set of public methods, but with distinct names qualified by the class name in which they are defined Data layout is combin
2、ed as well, with compile-time access control (e.g., private) still applies:Object Da1iiLutBase panDerived partObjed Mettad LiyoinBa-SE::Basej 弧e:aB葩&JDenmLDemdQDemDerrijedfiiid With inheritance, private data in the base class is still private C+ introduces the "protected clause” for allowin
3、g a derived class to have special access privileges to the base class. Protected data and methods are only visible to base classes. Use protected data and methods to selectively break encapsulation so that the subclass can access the data and/or methods. NOTE: when you construct a composite object,
4、the base class constructor is executed before the derived class constructor. That is objects are constructed from the base down the inheritance hierarchy. Usually, destruction is the reversea derived class destructor is executed before a base class destructor. Inheritance Example When a derived clas
5、s is constructed, the base class constructor is executed prior to the derived class constructor. Thus the derived class can pass arguments to the base class constructor using the initialize list.include<iostream.h>#include<conio.h>class Baseprivate:int x;public:Base() : x(0) cout«11
6、 nnnDefault BaseBase(int x) : x(x)cout«Hnnnparameter Base x=H«x Base()cout«nnnnDestructor is called11;class Derived : public Baseprivate:int y;char *s;public:Derived(): Base(), y(O),s(NULL) cout«11 nnnDefault derived class called y= n«y;Derived(int x, int y): Base(x), y(0), s(NULL)cout«HnnnDerived parameter is called x=n«x«n,y=M«y;Derived。cout«1 fnnnDerived destructor is called11;void main() clrscr();Base a;Base b(l
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025江西吉安吉州区北门街道真君山社区招聘就业见习人员1人模拟笔试试题及答案解析
- 2026湖南长沙市达德中学公开招聘校聘教师考试备考题库及答案解析
- 2025吉林长春市德惠市大学生乡村医生专项计划招聘2人(1号)模拟笔试试题及答案解析
- 2025福建福州滨海实验学校临聘教师招聘1人(提供住宿还有食堂)备考考试试题及答案解析
- 深度解析(2026)《GBT 25995-2010精细陶瓷密度和显气孔率试验方法》
- 深度解析(2026)GBT 25934.3-2010高纯金化学分析方法 第3部分:乙醚萃取分离ICP-AES法 测定杂质元素的含量
- 2025山东德州临邑县人民医院招聘备案制工作人员15人备考考试题库及答案解析
- 2025江西省财通供应链金融集团有限公司第二批次社会招聘2人模拟笔试试题及答案解析
- 深度解析(2026)《GBT 25743-2010钢件深冷处理》
- 2025新疆青河县社保中心综柜岗位见习生招聘1人参考考试题库及答案解析
- 【MOOC】数据结构与算法-北京大学 中国大学慕课MOOC答案
- MOOC 理解马克思-南京大学 中国大学慕课答案
- 安全工器具登记台账
- 《荷塘月色》《故都的秋》比较阅读-统编版高中语文必修上册
- 足浴店消防安全的应急预案范文
- 中央电大护理专业本科通科实习出科考核病历
- 卫生院基本公共卫生服务奖惩制度
- 气动冲床设备日常点检标准作业指导书
- β-丙氨酸补充对运动能力的影响
- 南昌工程学院水电站课程设计
- CAD工艺流程图用图形符号
评论
0/150
提交评论