版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【智慧养老】养老社区智能环境安全风险分析与预警平台解决方案
- 单词词汇竞赛活动总结
- 2026智慧养老整体智能化系统汇报方案
- 2026年新高考全国卷生物易错概念押题卷含解析
- 2026年新课标II卷高考语文压轴题型集训卷含解析
- 2026年新高考化学押题模拟卷易错题训练(含解析)
- 步步高物流成本管控
- 水下钻井设备操作工创新实践模拟考核试卷含答案
- 角平分线的性质课件2025-2026学年八年级数学上册(湘教版)
- 轴承装配工操作评估能力考核试卷含答案
- 《生物制药导论》 课件 第七章 生物制药设备与车间设计
- 【T8联考】2026届高三4月阶段练习(湖北版)物理+答案
- 第13课+资本主义世界殖民体系的建立与亚非拉民族独立运动+2025-2026学年中职高一下学期高教版(2023)世界历史全一册
- HSK1级课件教学课件
- (2025版)国家基层高血压防治管理指南2025版解读课件
- 老年人术后谵妄预防与质量控制方案
- 2025年摇滚音乐节举办项目可行性研究报告及总结分析
- 面部徒手整容培训课件
- 2025年全国统一高考数学试卷(全国一卷)含答案
- 2025春国家开放大学农产品电子商务-形考任务123参考答案
- 九年级数学上册第四章图形的相似7相似三角形的性质教案新版北师大版
评论
0/150
提交评论