Chapter 9: Objects and Classes

Similar documents
KillTest 质量更高 服务更好 学习资料 半年免费更新服务

Microsoft Word - 第3章.doc

Microsoft Word - ch04三校.doc

新・解きながら学ぶJava

Microsoft PowerPoint - plan08.ppt

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

JavaIO.PDF

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

FY.DOC

Java

untitled

Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Obj

Chapter 9: Objects and Classes

chp6.ppt


使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款

2009年3月全国计算机等级考试二级Java语言程序设计笔试试题

Microsoft PowerPoint - ch6 [相容模式]

利用Java技术编写桌面软件基础

基于CDIO一体化理念的课程教学大纲设计

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

Microsoft PowerPoint - plan06.ppt

untitled

EJB-Programming-3.PDF

Strings

untitled

untitled

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

untitled

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

JAVA String常用APi

エスポラージュ株式会社 住所 : 東京都江東区大島 東急ドエルアルス大島 HP: ******************* * 关于 Java 测试试题 ******

EJB-Programming-4-cn.doc

(6) 要 求 付 款 管 理 员 从 预 订 表 中 查 询 距 预 订 的 会 议 时 间 两 周 内 的 预 定, 根 据 客 户 记 录 给 满 足 条 件 的 客 户 发 送 支 付 余 款 要 求 (7) 支 付 余 款 管 理 员 收 到 客 户 余 款 支 付 的 通 知 后, 检

untitled

untitled

Microsoft Word - 物件導向編程精要.doc

Strings

2 Java 语 言 程 序 设 计 教 程 简 单 性 Java 语 言 的 语 法 与 C 语 言 和 C++ 语 言 很 接 近, 使 得 大 多 数 程 序 员 很 容 易 学 习 和 使 用 Java 另 一 方 面,Java 丢 弃 了 C++ 中 很 少 使 用 的 很 难

软件工程文档编制

CHAPTER VC#

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

javaexample-02.pdf

untitled

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

Microsoft Word - chap10.doc

Microsoft Word - 01.DOC

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

java2d-4.PDF

3.1 num = 3 ch = 'C' 2

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

C++ 程式設計

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

Swing-02.pdf

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

obj-c_4.key

Microsoft PowerPoint - course2.ppt

2_S_new

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数

Learning Java

extend

untitled

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

untitled

无类继承.key

untitled

(procedure-oriented)?? 2

科学计算的语言-FORTRAN95

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

Microsoft PowerPoint - L17_Inheritance_v4.pptx

《大话设计模式》第一章

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

Java 1 Java String Date

Microsoft Word - 第6章.doc

Chapter12 Derived Classes

Microsoft Word - Learn Objective-C.doc

Microsoft Word - (web)_F.1_Notes_&_Application_Form(Chi)(non-SPCCPS)_16-17.doc

SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 "odps-sdk" 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基

untitled

The Embedded computing platform

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

CHAPTER 1

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

附录J:Eclipse教程

c_cpp

Microsoft PowerPoint - ch02

全国计算机技术与软件专业技术资格(水平)考试

基于ECO的UML模型驱动的数据库应用开发1.doc

C/C++语言 - 运算符、表达式和语句

C/C++ - 函数

mvc

摘 要 本 校 多 媒 體 設 計 系 與 上 海 戲 劇 學 院 創 意 學 院 在 多 次 聯 繫 交 流 之 下, 已 簽 署 合 作 備 忘 錄, 積 極 尋 求 兩 校 合 作 教 學 與 共 同 創 作 之 機 會 藉 由 本 系 學 生 作 品 腦 殘 公 寓 入 圍 第 五 屆 中

RunPC2_.doc

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

e bug 0 x=0 y=5/x 0 Return 4 2

09 (File Processes) (mkdir) 9-3 (createnewfile) 9-4 (write) 9-5 (read) 9-6 (deletefile) 9-7 (deletedir) (Exercises)

没 有 多 余 的 Contruol 或 Action 了 原 来 Domain 层 被 服 务 层 Service layer 遮 挡, 在 右 边 图 中, 则 Domain 层 直 接 暴 露 给 前 台 了, 没 有 被 遮 挡, 裸 露 了 这 样 一 步 到 位 实 现 领 域 模 型

OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

Transcription:

Fortran Algol Pascal Modula-2 BCPL C Simula SmallTalk C++ Ada Java C#

C Fortran

5.1

message A B

5.2

1 class Vehicle subclass Car object mycar

public class Vehicle extends Object{ public int WheelNum = 4; //...// } import Vehicle; public class Car extends Vehicle{ public int DoorNum = 4 ; public String EngineType = "V6" ;...// } import java.io.*; import Car; public class Me{ public static void main(string args[]){ Car mycar = new Car(); System.out.printlin(" "+mycar.wheelnum); System.out.printlin(" "+mycar.enginetype); } }

Circle radius Graphical notation for classes findarea new Circle() new Circle() circle1: Circle radius = 2... circlen: Circle radius = 5 Graphical notation for objects

2 class Circle { double radius = 1.0; } double findarea() { return radius*radius*3.14159; }

5.3

class Car { int color_number; int door_number; int speed; } void brake() { } void speedup() { }; void slowdown() { }

5.4 ClassName objectname; Example: Car mycar; Circle mycircle; objectname = new ClassName(); Example: mycar = new Car(); mycircle = new Circle();

ClassName objectname = new ClassName(); Example: Car mycar = new Car(); Circle mycircle = new Circle();

5.5 Primitive type int i = 1 i 1 Object type Circle c c reference Created using new Circle(5) c: Circle radius = 5

Primitive type assignment i = j Object type assignment c1 = c2 Before: After: Before: After: i 1 i 2 c1 c1 j 2 j 2 c2 c2 c1: Circle c2: Circle radius = 5 radius = 9

Primitive type assignment i = j Object type assignment c1 = c2 Before: After: Before: After: i 1 i 2 c1 c1 j 2 j 2 c2 c2 c1: Circle radius = 5 c2: Circle radius = 9

5.6 static final static

Notation: +: public variables or methods -: private variables or methods underline: static variables or metods Memory radius is an instance variable, and numofobjects is a class variable Circle -radius -numofobjects +getradius +setradius +getnumofobjects +findarea instantiate instantiate circle1:circle -radius = 1 -numofobjects = 2 circle2:circle -radius = 5 -numofobjects = 2 1 radius 2 5 radius numofobjects

Example numofobjects Circle Circle private double radius private static int numofobjects public double getradius( ) public void setradius(double newradius) public static int getnumofobjects( ) public double findarea( ) TestInstanceAndClassVariable Run

5.7 : objectname.data mycircle.radius : objectname.method mycircle.findarea()

Example 5.1 Circle TestCircle Run

5.8 void new

5.8 Circle(double r) { radius = r; } Circle() { radius = 1.0; } mycircle = new Circle(5.0);

Example 5.2 Circle TestCircleWithConstructors Run

5.9 Example 5.3 TestPassingObject Run

mycircle n main printareas n mycircle main 5 mycircle Circle radius=1 printareas times c 5

5.10 Java public. private. getter and setter

Example 5.4 private Circle getradius and setradius TestCircleWithPrivateModifier Run

5.11 Java { { }}

class A{ int x; int f() { int a=5; x=a; // x } int g() { int y; y=a;// aga } }

class Tom{ int x=98,y; void f() { int x=3; y=x; //y 3 98 } }

5.12 this super this this this super Java super

Example 5.6 this super class A { int a; A(int new_value) { a = new_value; } } class B extends A { int b, c; B() { this(2, 3); } B(int new_b, int new_c) { super(1); b = new_b; c = new_c; } }

class Demo { public static void main(string[] args) ) { B obj_b = new B(); System.out.println("a= = "+obj_b.a + "; b= "+obj_b.b + "; c= "+ obj_b.c); } } a= 1; b= 2; c= 3

5.13 5.13.1 5.13.2 5.13.3

5.13.1 Student 5.60 * Course 0.3 1 Faculty 3 5 60

5.13.1 Student 5.60 * Course 0.3 1 Faculty 3 5 60

5.13.1 Student 5.60 * Course 0.3 1 Faculty 3 5 60

5.13.1 Student 5.60 * Course 0.3 1 Faculty 3 5 60

5.13.1 Student 5..60 * Course 0..3 1 Faculty 3 5 60

5.13.1 Student 5..60 * Course 0..3 1 Faculty 3 5 60

5.13.2 (has-a) (part-of) (own) (employedby) Magazine * 1 Publisher * * Consultant

5.13.2 (has-a) (part-of) (own) (employedby) Magazine * 1 Publisher * * Consultant

5.13.3 (is-a) Person Student Faculty

5.7 5.14 1. 2. 3. 4.

Example 5.6 1 Name 1 Borrower Address 1 Mortgage

Example 5.6 The following is a test program that uses the classes Name, Address, Borrower, and Mortgage. BorrowMortgage Run

5.15 Java API and Core Java classes java.lang JavaObject String Math Number SystemJava java.awt java.applet applet

5.15 Java API and Core Java classes, cont. java.io java.util java.net

5.15 Java API and Core Java classes, cont. java.awt.image bitmap. java.awt.peer GUI Others: java.sql java.rmi

5.16 The String Class Javajava.lang String "student100", "China" C

5.16 The String Class String String s; = new String = s = new String ( "student" ); s = "student" String s = new String ( "student" ); String s = "student

5.16 The String Class String tom = "my name is tom"; String jane = "my name is jane"; tom.equals(jane) false String s = " I am"; String s2 = "a Chinese"; String s3, s4; s3 = s + s2; s4 = s + 24; 24

5.16 The String Class String s = "I am a Chinese"; String subs; subs = s.substring (7);//Chinese subs = s.substring (0,8);//I am a C length() String s = "student"; int len=s.length(); endindex beginindex, endindex

5.16 The String Class String String s = "I am a Chinese"; s.indexof("chinese" );// 7 s.indexof('a'); //2 Do not use message[0] s.charat(index) index 0 s.length()-1

5.17 The StringBuffer Class StringBuffer String.. StringBuffer String..

StringBuffer public StringBuffer() 16. public StringBuffer(int length) length. public StringBuffer(String str) string string 16.

StringBuffer StringBuffer StringBuffer strbuf = new StringBuffer(); strbuf.append("welcome"); strbuf.append(' to Java'); sb1.append( this is a book. ); sb1.insert(6,30); // int,char,double,string sb1.setcharat(0, a );

5.18 The StringTokenizer Class Constructors StringTokenizer(String s, String delim, boolean returntokens) delims StringTokenizer returntokens true

Class Constructors StringTokenizer(String s, String delim) delims StringTokenizer StringTokenizer(String s) s StringTokenizer

The StringTokenizer Class Methods boolean hasmoretokens() true String nexttoken() String nexttoken(string delim) delim public int counttokens() StringTokenizer

? this