版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、OOP Mega RecapClasses, objects, aliasing, methods, arrays, stringsObjects and classesObjects are “large” variablesGroup together multiple smaller primitive variablesObject variables themselves are aliases to the objectThe object itself is separate; its creation is a separate stepThe type of an objec
2、t is programmer definedcalled a classclass.type = variable;class = objectAccess member variablesmember variables using the . (dot) symbol.OOP Principle #0: Encapsulation (data hiding)Aliasing and Object ConstructionAn object variable doesnt contain the data itself!Object variables are hence called r
3、eference reference variablesvariablesThey referrefer to the objects present in memoryMultiple object variables can refer to the samesame object in memory!Object variable declaration: ;Assignment (=) creates aliases (not copies)Object creation = newnew ()();“new ()” is an expressiontype = class-namev
4、alue = alias to the newly created objectMethods (non-static)Can work on member variables of the objectA method is called “on an object”.method_name()The code inside a method can implicitly use member variablesThe member variables of the given object are usedStatic vs Non-static methodsstatic void me
5、thod_name(int parameter) /statements No object context to work with (simple)static void method_name(Rectangle r, int parameter) Explicit object context to work with (indirect, cumbersome)void method_name(int parameter)/ access member variablesImplicit object contextThe ConstructorA special methodNam
6、ed after the class name.Takes input parameters; no return typeno return type.Used to initialize an object at creation time.class RectangleRectangle(int w, int h)/statements;Multiple methods and recursionMethods of a class can call each other directlyEach implicitly use the same object contextsame ob
7、ject context.Recursive calls also implicitly use the same object same object contextcontext.The this keywordA special read-onlyread-only variable visible inside methodsAlias to the object context in useOrganizing and Reusing classesDependency relationship between classesMotivated by the dependency b
8、etween methodsHow should we re-use classes?Wrong Answer: Use copy and paste Trivial Answer: use objects of some classes inside other classesOOP Answer: Inheritance of classesParent-Child like relationship between classeseg. Parallelogram and Rectangle classesOOP feature #1:InheritanceDefine a new (“
9、child”) class based on a “parent” classThe new class has an implicit copy of the old class in itAdd member variables and re-define (override) some methodsUse the “super” alias to access parent class methodsMainly for calling parents constructor and overridden methodsImplicit copy of parents member v
10、ariablesThe child class gets a copy of the parents member variablesUse them freely as if they were defined in the child class itselfImplicit presence of parents methodsFreely use parents methodsThey work on the copy of parents member variables in the child classInheritance:Java syntaxclass extends /
11、 declarations for child class/ access parent version of overridden methodsuper.()/ access parents constructor/ must be first statement in child constructorsuper();Note: a child class can have a sub-child class and so on The “Object” classIts the parent class of allall classesImagine Java automatically adding an “extends Object”methods in ObjectString toString()returns a string rep
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 化工厂充装人员课件培训
- 《汽车文化》课件 第二章 汽车基本结构 第一节 汽车的分类
- 福建省泉州市第五中学2025-2026学年上学期期末七年级数学试卷(无答案)
- 2026年陕西省西安市碑林区西北工大附中中考数学第一次适应性试卷(含简略答案)
- 2026年度牛市下半场实物再通胀
- 钢结构焊接材料选用技术要点
- 2026年上半年黑龙江事业单位联考省人民政府黑瞎子岛建设和管理委员会招聘4人备考考试题库及答案解析
- 2026内蒙古鄂尔多斯市城投商业运营管理有限公司招聘46人参考考试题库及答案解析
- 市场调研公司数据管理制度
- 2026湖南株洲市天元中学招聘编外合同制教师考试备考试题及答案解析
- 电磁辐射环境下的职业健康防护
- 中药外洗治疗化疗导致外周神经毒课件
- 2025-2026学年人教版(新教材)小学数学三年级下册(全册)教学设计(附目录P208)
- 2025版中国慢性乙型肝炎防治指南
- 2026年及未来5年市场数据中国草酸行业发展前景预测及投资战略数据分析研究报告
- 感染科结核病防治培训指南
- 金属水幕施工方案(3篇)
- 2025美国心脏协会心肺复苏(CPR)与心血管急救(ECC)指南解读
- 2024-2025学年浙江省金华市兰溪市一年级(上)期末数学试卷
- 广东省珠海市香洲区2023-2024学年八年级上学期语文期末试卷(含答案)
- 2025年青海省辅警考试公安基础知识考试真题库及参考答案
评论
0/150
提交评论