预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共37页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

第11讲面向对象编程基础(2)本讲内容一、值类型与引用类型值类型与引用类型值类型与引用类型 多个实例共享一个型,但各自存储自己的属性二、继承与多态概况请开“马自达车”!从“有病”说起#include<stdio.h> voidPrintHelp(); voidDriveVolvo(); voidDriveBenz(); voidDriveMazda(); main(intargc,char*argvs[]) { if(argc<2){ PrintHelp(); return; } if(strcmp(argvs[1],"V")==0) DriveVolvo(); elseif(strcmp(argvs[1],"B")==0) DriveBenz(); elseif(strcmp(argvs[1],"M")==0) DriveMazda(); else PrintHelp();解决办法什么是“继承”机动车Musician单继承与多继承“继承”关系的代码实现继承(续)usingSystem; publicclassBase { publicinta=10; } publicclassDerived:Base { } publicclassClient { publicstaticvoidMain() { Derivedd=newDerived(); Console.WriteLine(d.a); } }usingSystem; publicclassBase { publicstaticinta=10; } publicclassDerived:Base { } publicclassClient { publicstaticvoidMain() { Derived.a=15; Console.WriteLine(Base.a); } }usingSystem; publicclassBase { publicvoidSayHello() { Console.WriteLine("Hello!"); } } publicclassDerived:Base { } publicclassClient { publicstaticvoidMain() { Derivedd=newDerived(); d.SayHello(); } }usingSystem; publicclassBase { publicstaticvoidSayHello() { Console.WriteLine("Hello!"); } } publicclassDerived:Base { } publicclassClient { publicstaticvoidMain() { Derived.SayHello(); } }usingSystem; publicclassBase { privateinta=10; publicvoidShowA() { Console.WriteLine(a); } } publicclassDerived:Base { } publicclassClient { publicstaticvoidMain() { Derivedd=newDerived(); d.ShowA(); } }继承(续)多态(PolyMorphism)“多态”案例“多态”案例(续)多态特点面向对象三要素面向对象学习顺序小结小结(续)