ch面向对象程序设计基础

ch面向对象程序设计基础

ID:12546158

大小:192.00 KB

页数:45页

时间:2018-07-17

ch面向对象程序设计基础_第1页
ch面向对象程序设计基础_第2页
ch面向对象程序设计基础_第3页
ch面向对象程序设计基础_第4页
ch面向对象程序设计基础_第5页
资源描述:

《ch面向对象程序设计基础》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、第三章面向对象程序设计基础士有百折不挠之真心,方有万变不穷之妙用天下本无难事,心以为难,斯乃真难。苟不存一难之见于心,则运用之术自出第一节面向对象程序设计一、面向过程的程序设计1、作什么通过函数完成2、如何做函数串在一起二、面向对象的设计方法1、找对人、物2、分析行为、属性3、如何做三、对象(object)的讨论对象是对现实世界的描述对象有以下特性:1、万物皆为对象2、每个对象都是唯一的3、对象具有属性和行为4、对象都属于某个类四、抽象的概念抽象是指从特定角度出发,从已经存在的一些事物中,抽取我们所关注特

2、性形成一个新的事物的思维过程。1.从问题领域的事物到软件模型中的对象的抽象2.从对象到类的抽象3.从子类到父类的抽象五、类的概念(class)类是一组具有相同属性和行为的对象的抽象。第二节类及对象的创建一、类的定义类是数据和函数的集合。类是一种类型。类是Java语言基本元素,类由成员变量和方法组成;类定义的一般形式如下:class类名{变量(常量)定义构造方法定义方法定义}其中访问权限为public、private、protected或取默认值。publicclassStudentTest{publics

3、taticvoidmain(Stringargs[]){StudentstudentA=newStudent();StudentstudentB=newStudent();studentA.setId("20001");studentA.setName("张三");studentA.setChinese(90);studentA.setMath(80);studentB.setId("20001");studentB.setName("张三");studentB.setChinese(90);studen

4、tB.setMath(85);System.out.println(studentA.Sum());System.out.println(studentB.Sum());}publicclassStudent{privateStringid;privateStringname;privateintmath;privateintchinese;publicvoidsetId(Stringid){this.id=id;}publicvoidsetName(Stringname){this.name=name;

5、}publicvoidsetMath(intmath){this.math=math;}publicvoidsetChinese(intchinese){this.chinese=chinese;}publicintSum(){returnmath+chinese;}}例题2:publicclassStudent{privateStringid;privateStringname;privateintmath;privateintchinese;publicStringgetId(){returnid;}

6、publicStringgetName(){returnname;}publicintgetMath(){returnmath;}publicintgetChinese(){returnchinese;}publicvoidsetId(Stringid){this.id=id;}publicvoidsetName(Stringname){this.name=name;}publicvoidsetMath(intmath){this.math=math;}publicvoidsetChinese(intch

7、inese){this.chinese=chinese;}publicintSum(){returngetMath()+getChinese();}}publicclassStudentTest{publicstaticvoidmain(Stringargs[]){StudentstudentA=newStudent();StudentstudentB=newStudent();studentA.setId("20001");studentA.setName("张三");studentA.setChine

8、se(90);studentA.setMath(80);studentB.setId("20002");studentB.setName("张三");studentB.setChinese(90);studentB.setMath(85);System.out.println("name:"+studentA.getName()+"tId:"+studentA.getId()+"tscore:"+studentA.Sum(

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。