第4章 类和对象.ppt_第1页
第4章 类和对象.ppt_第2页
第4章 类和对象.ppt_第3页
第4章 类和对象.ppt_第4页
第4章 类和对象.ppt_第5页
免费预览已结束,剩余38页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 第4章类和对象 成员概述 2 成员概述 classComplexNumber publicdoublea 0 publicdoubleb 0 ComplexNumberc1 newComplexNumber 声明 创建对象 成员概述 3 成员种类数据成员函数成员嵌套成员 成员概述 成员访问限制private私有 4 classStudent privatestringname privatevoidWrite Console WriteLine name Students1 newStudent Console WriteLine s1 name s1 Write 成员概述 成员访问限制private私有public公有 5 classStudent publicstringname publicvoidWrite Console WriteLine name Students1 newStudent Console WriteLine s1 name s1 Write 成员概述 成员访问限制private私有public公有protected保护 6 classStudent protectedstringname protectedvoidWrite Console WriteLine name classGraduate Student publicvoidOutput Console WriteLine name Write 成员概述 成员访问限制private私有public公有protected保护internal内部 7 namespaceAsm1 internalclassStudent namespaceAsm2 classLibrary publicvoidGet Asm1 Students1 newAsm1 Student 成员概述 成员访问限制private私有public公有protected保护internal内部 8 namespaceAsm1 publicclassStudent namespaceAsm2 classLibrary publicvoidGet Asm1 Students1 newAsm1 Student 成员概述 静态成员与非静态成员实例成员 非静态 9 classStudent publicstringname Students1 newStudent Console WriteLine s1 name 成员概述 静态成员与非静态成员实例成员 非静态 静态成员 10 classStudent publicstringname publicstaticstringschool Students1 newStudent Console WriteLine s1 name Console WriteLine Student school 成员概述 静态成员与非静态成员实例成员 非静态 静态成员 11 classStudent publicstringname publicstaticstringschool publicstaticvoidWrite Console WriteLine name 成员概述 字段一般字段 12 publicclassCircle publicdoubler Circlec1 newCircle Console WriteLine c1 r c1 r 10 成员概述 字段一般字段常量字段 13 publicclassCircle publicdoubler publicconstdoublePI 3 14 Circlec1 newCircle Console WriteLine c1 r c1 r 10 Console WriteLine Circle PI Circle PI 3 1416 成员概述 字段一般字段常量字段只读字段 14 publicclassCircle publicdoubler publicreadonlydoublePI 3 14 Circlec1 newCircle Console WriteLine c1 r c1 r 10 Console WriteLine c1 PI c1 PI 3 1416 方法 15 方法声明 publicintMax intx inty returnx y x y 返回类型 方法名 参数列表 执行体 方法 参数类型值传递 16 publicvoidSwap intx inty intz x x y y z inta 10 intb 20 Swap a b 方法 参数类型值传递 17 publicvoidSwap intx inty intz x x y y z inta 10 intb 20 Swap a b 方法 参数类型值传递引用传递 18 publicvoidSwap refintx refinty intz x x y y z inta 10 intb 20 Swap a b 方法 参数类型值传递引用传递 19 publicvoidSwap refintx refinty intz x x y y z inta 10 intb 20 Swap a b 方法 参数类型值传递引用传递输出型参数 20 publicintSumProd intx inty outinta a x y returnx y 方法 参数类型值传递引用传递输出型参数数组型参数 21 publicintSum paramsint x ints 0 for inti 0 i x Length i s x i returns int x 1 3 5 7 9 ints1 Sum x ints2 Sum 2 4 6 8 10 类的特殊方法 构造函数 22 publicclassStudent publicintage 18 Students1 newStudent s1 age 20 类的特殊方法 构造函数无参构造函数 23 publicclassStudent publicintage publicStudent age 18 Students1 newStudent s1 age 20 类的特殊方法 构造函数无参构造函数带参构造函数 24 publicclassStudent publicintage publicStudent inti age i Students1 newStudent 20 类的特殊方法 构造函数无参构造函数带参构造函数静态构造函数 25 publicclassStudent publicintage publicstaticstringschool staticStudent school 华中理工大学 类的特殊方法 构造函数无参构造函数带参构造函数静态构造函数析构函数 26 publicclassStudent publicstringname Student Console Write 学生对象 0 销毁 name 类的特殊方法 属性getset 27 publicclassStudent privatestringname publicstringName get returnname set name value 类的特殊方法 索引函数getset 28 publicclassSchool privateStudent students publicStudentthis intindex get returnstudents index set students index value 类的特殊方法 操作符 29 intx 2 inty 3 intz x y 预定义操作 自定义操作 ComplexNumberc1 newComplexNumber 2 4 ComplexNumberc2 newComplexNumber 3 6 ComplexNumberc3 c1 c2 类的特殊方法 操作符 30 publicstaticComplexNumberoperator ComplexNumberc1 ComplexNumberc2 returnnewComplexNumber c1 a c2 a c1 b c2 b 类的特殊方法 操作符一元操作符二元操作符 31 T turefalse this对象引用 this 32 publicclassComplexNumber privatedoublea privatedoubleb publicComplexNumber doublea doubleb this a a this b b publicvoidOutput Console Write 0 1 i this a this b b 常用类型 ObjectToString GetType 33 objecto1 newobject console WriteLine o1 GetType o1 abc Console WriteLine o1 GeType System Object System String 常用类型 ObjectToString GetType Equals 34 objecto1 newobject Students1 newStudent console Write o1 s1 o1 s1 Console Write o1 s1 false true 常用类型 String创建对象 35 strings1 VisualC strings2 newstring M 3 char v V i s u a l strings3 newstring v strings4 newstring v 0 3 常用类型 String创建对象字符操作 36 strings1 Apple inti s1 IndexOf p i s1 LastIndexOf p s1 s1 ToUpper s1 s2 Replace P A 1 APPLE 2 AAALE 常用类型 String创建对象字符操作子串操作 37 strings1 Software inti s1 IndexOf ware strings2 s1 SubString 0 4 strings3 s2 Insert 0 Micro s1 s2 Replace soft sun 4 soft Microsoft MicroSun 常用类型 String创建对象字符操作子串操作格式化和解析 38 strings1 string Format 0 年级 0 班 3 intx 8 s1 string Format 0 年 1 月 08 x s1 string Format 0 C3 元 9999 常用类型 String创建对象字符操作子串操作格式化和解析 39 对象 字符串 classComplexNumber doublea b publicoverridestringToString returnstring Format 0 1 a b publicstaticComplexNumberParse strings string ss s Split doublea double Parse ss 0 doubleb double Parse ss 1 returnnewComplexNumber a b 常用类型 StringBuilder 40 strings1 for inti 0 i 100 i s1 i ToString StringBuilders1 newStringBuilder for inti 0 i 100 i s1 Append i 低性能 高性能 常用类型 Math取整函数 Abs Ceiling Floor Round指数和对数函数 Exp Pow Log Log10三角函数 Sin Cos Tan Asin Acos Atan 41 常用类型 Da

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论