Thinking in Java chapter6 笔记和习题

Size: px
Start display at page:

Download "Thinking in Java chapter6 笔记和习题"

Transcription

1 Thinking in Java chapter6 笔记和习题 emacsun 目录 1 简介 1 2 默认的 constructor 和带参数的 constructor 2 3 从 constructor 的定义引入函数重载 4 4 默认的 constructor 7 5 this 的作用 9 6 理解 static 10 7 class 成员初始化 10 8 初始化顺序 11 9 static 类型的初始化 显示初始化 非静态实例初始化 数组初始化 20 1 简介 Initialization and Cleanup 这一章首先讲述类初始化的一些操作, 顺带 初始化操作阐述了方法重载 然后讲述了轊轡轶轡的轇轡轲轢轡轧轥轃软转转轥轣轴软轲机制 其中 輱

2 輲默认的 CONSTRUCTOR 和带参数的 CONSTRUCTOR 关于 static 初始化的例子最为令人印象深刻, 我把那个 橱柜 的代码做了逐行解析, 学完之后感觉非常顺畅 2 默认的 constructor 和带参数的 constructor 首先默认的 constructor, 看代码 : import java.util.*; import static net.mindview.util.print.*; class Rock{ Rock(){ System.out.println("Rock"); public class SimpleConstructor { public static void main(string args[]) { for (int i=0; i < 10 ;i++) { new Rock(); 注意輺 constructor 是一个函数, 其名称和 class 的名称必须相同輨没有为什么, 这是规定輩 但是没有说明这个函数可不可以携带参数, 实际上是可以的, 继续看代码 : import java.util.*; import static net.mindview.util.print.*; class Rock{ Rock(int i){ System.out.print("Rock" + i); 輲輯輲輵

3 輲默认的 CONSTRUCTOR 和带参数的 CONSTRUCTOR public class SimpleConstructor2 { public static void main(string args[]) { for (int i=0; i < 10 ;i++) { new Rock(i); 这段代码的输出是輺 Rock 0 Rock 1 Rock 2 Rock 3 Rock 4 Rock 5 Rock 6 Rock 7 Rock 8 Rock 9 注意在这段代码中使用了 print 而不是 println 輮 print 输出默认不带回车 ; println 输出默认带回车 constructor 函数没有返回值, 注意这里的没有返回值和 void 函数是两回事 String 对象初始化值是 null 輬看代码 : import java.util.*; import static net.mindview.util.print.*; class Rock{ String str; public class Exercise0601 { public static void main(string args[]) { Rock rcok = new Rock(); print("" + rcok.str); 其输出为 null 輳輯輲輵

4 3 从 constructor 的定义引入函数重载 輳从 CONSTRUCTOR 的定义引入函数重载 作者从 constructor 过度到另一个知识点 overload 輬平滑自然 对于重载, 值得注意的是 primitive 类型的重载 看代码 : import static net.mindview.util.print.*; public class PrimitiveOverloading{ void f1(char x){printnb("f1(char) "); void f1(byte x){printnb("f1(byte) "); void f1(short x){printnb("f1(short) "); void f1(int x){printnb("f1(int) "); void f1(long x){printnb("f1(long) "); void f1(float x){printnb("f1(float) "); void f1(double x){printnb("f1(double) "); void f2(byte x){printnb("f2(byte) "); void f2(short x){printnb("f2(short) "); void f2(int x){printnb("f2(int) "); void f2(long x){printnb("f2(long) "); void f2(float x){printnb("f2(float) "); void f2(double x){printnb("f2(double) "); void f3(short x){printnb("f3(short) "); void f3(int x){printnb("f3(int) "); void f3(long x){printnb("f3(long) "); void f3(float x){printnb("f3(float) "); void f3(double x){printnb("f3(double) "); void f4(int x){printnb("f4(int) "); void f4(long x){printnb("f4(long) "); void f4(float x){printnb("f4(float) "); void f4(double x){printnb("f4(double) "); void f5(long x){printnb("f5(long) "); 輴輯輲輵

5 輳从 CONSTRUCTOR 的定义引入函数重载 void f5(float x){printnb("f5(float) "); void f5(double x){printnb("f5(double) "); void f6(float x){printnb("f6(float) "); void f6(double x){printnb("f6(double) "); void f7(double x){printnb("f7(double) "); void testconstval(){ printnb("5: "); f1(5);f2(5);f3(5);f4(5);f5(5);f6(5);f7(5);print(); void testchar(){ char x = x ; printnb("char: "); f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);print(); void testbyte(){ byte x = 0; printnb("byte: "); f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);print(); void testshort(){ short x = 0; printnb("short: "); f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);print(); void testint(){ int x = 0; 輵輯輲輵

6 輳从 CONSTRUCTOR 的定义引入函数重载 printnb("int: "); f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);print(); void testlong(){ long x = 0; printnb("long: "); f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);print(); void testfloat(){ float x = 0; printnb("float: "); f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);print(); void testdouble(){ double x = 0; printnb("double: "); f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);print(); public static void main(string[] args){ PrimitiveOverloading p = new PrimitiveOverloading(); p.testconstval(); p.testchar(); p.testbyte(); p.testshort(); p.testint(); p.testlong(); p.testfloat(); p.testdouble(); 輶輯輲輵

7 这段代码的输出是輺 輴 默认的 CONSTRUCTOR 5: f1(int) f2(int) f3(int) f4(int) f5(long) f6(float) f7(double) char: f1(char) f2(int) f3(int) f4(int) f5(long) f6(float) f7(double) byte: f1(byte) f2(byte) f3(short) f4(int) f5(long) f6(float) f7(double) short: f1(short) f2(short) f3(short) f4(int) f5(long) f6(float) f7(double) int: f1(int) f2(int) f3(int) f4(int) f5(long) f6(float) f7(double) long: f1(long) f2(long) f3(long) f4(long) f5(long) f6(float) f7(double) float: f1(float) f2(float) f3(float) f4(float) f5(float) f6(float) f7(double) double: f1(double) f2(double) f3(double) f4(double) f5(double) f6(double) f7(double) 4 默认的 constructor 默认的 constructor 是没有参数的 如果定义类时没有指定构造函数, 那 么编译器会生成一个默认的构造函数 如果在定义类时指定了构造函数, 那么 在创建该类的对象时就需要指定该对象实用的构造函数, 而不能使用默认构造 函数, 否则就会报错 看代码 : 輱 class Bird { 輲 Bird ( int i ){ 輳 Bird ( double d ){ 輴 輵 public class NoSynthesis { 輶 public static void main ( String [] args ){ 輷 Bird b2 = new Bird (1); 輸 Bird b3 = new Bird (1.0); 輹 Bird b4 = new Bird (); 輱輰 輱輱 这个代码会报错 : error: no suitable constructor found for Bird(no arguments) Bird b4 = new Bird(); ^ constructor Bird.Bird(int) is not applicable (actual and formal argument lists differ in length) constructor Bird.Bird(double) is not applicable (actual and formal argument lists differ in length) 輷輯輲輵

8 1 error 輴 默认的 CONSTRUCTOR 编译器会认为没有无参数的构造函数定义 对代码进行修改 : 輱 class Bird { 輲 Bird ( int i ){ 輳 Bird ( double d ){ 輴 輵 public class NoSynthesis { 輶 public static void main ( String [] args ){ 輷 Bird b2 = new Bird (1); 輸 Bird b3 = new Bird (1.0); 輹 輱輰 就没有报错 但是, 看代码 : 輱 class Bird { 輲 Bird ( int i ){ 輳 Bird ( double d ){ 輴 輵 public class NoSynthesis { 輶 public static void main ( String [] args ){ 輷 Bird b2 = new Bird (1); 輸 Bird b3 = new Bird (1.0); 輹 Bird b4; 輱輰 輱輱 这个代码也没有报错, 但是我不知道 b4 调用了那个构造函数 为了确认一下, 对代码做如下修改 : 輱 class Bird { 輲 Bird ( int i){ 輳 System. out. println (" with int i"); 輴 輵 Bird ( double d){ 輶 System. out. println (" with double d"); 輷 輸 輹 public class NoSynthesis { 輱輰 public static void main ( String [] args ){ 輱輱 Bird b2 = new Bird (1); 輱輲 Bird b3 = new Bird (1.0); 輱輳 Bird b4; 輱輴 輱輵 输出为輺 with int i with double d 輸輯輲輵

9 輵 THIS 的作用 可见 Bird b4 没有调用给出的两个构造函数, 而是用的默认的构造函数 5 this 的作用 简而言之, this 用来代表当前的对象 在使用的过程中, 你完全可以 用 this 来替代当前的对象 但是 this 的实用也会有一些限制, 比如只能 在 non-static 的方法中使用 但是在一个类的多个方法中不需要显示的使用 this 来指示当前类 this 的一个经常用到的地方是 return 语句返回一个对象 看代码 : 輱 public class Leaf { 輲 int i =0; 輳 Leaf increament (){ 輴 i ++; 輵 return this ; 輶 輷 void print (){ 輸 System. out. println (" i = " + i); 輹 輱輰 public static void main ( String [] args ){ 輱輱 Leaf x = new Leaf (); 輱輲 x. increament (). increament (). print (); 輱輳 輱輴 结果输出为 : i = 2 this 也可以用来把当前的对象传递给另外的方法, 看代码 : 輱 class Person { 輲 public void eat ( Apple apple ){ 輳 Apple peeled = apple. getpeeled (); 輴 System. out. println (" Yummy "); 輵 輶 輷輸 class Peeler { 輹 static Apple peel ( Apple apple ){ 輱輰 //... remove peel 輱輱 return apple ; 輱輲 輱輳 輱輴輱輵 class Apple { 輱輶 Apple getpeeled (){ return Peeler. peel ( this ); 輱輷 輱輸 輹輯輲輵

10 輱輹 public class PassingThis { 輲輰 public static void main ( String [] args ){ 輲輱 new Person (). eat ( new Apple ()); 輲輲 輲輳 輷 CLASS 成员初始化 this 还可以用来从一个 constructor 中调用另一个 constructor 这一用途有两点需要注意 : 輱輮你不能在一个 constructor 中调用两次 this 初始化函数 輲輮在一个 constructor 中, 如果要使用 this, 第一行有效代码就应该是使用 this 的代码 6 理解 static 有了 this 我们现在可以更深刻的理解 static 我们可以从 non-static 函数里调用 static 函数, 但是不能从 static 函数里调用 non-static 函数 为什么輿因为在 static 函数里没有对象的概念 static 函数依赖于 class 的定义存在, 而不依赖于对象的存在 所以 static 看起来就像是一个全局方法, 不依赖于对象存在 但是 Java 中是没有全局函数的, 所以通过 static 可以实现类似的效果 正是因为 static 的这个特性, 人们诟病 Java 的 static 方法不是面向对象的 因为在 static 方法中, 无法像一个对象发消息, 因为根本没有 this 因此当你的代码中有很多 static 的时候, 你要重新审视一下你的代码结构 但是在很多时候 static 又是一个不得不存在的特性, 在以后的章节中就会看到 7 class 成员初始化 Java 中对于 class 的基础类型成员都做了默认初始化 这说明, 每一个基 础类成员都有一个默认的构造函数, 为其赋初值 看代码 : 輱 import static net. mindview. util. Print.*; 輲輳 public class InitialValues { 輴 boolean t; 輵 char c; 輶 byte b; 輷 short s; 輱輰輯輲輵

11 輸 初始化顺序 輸 int i; 輹 long l; 輱輰 float f; 輱輱 double d; 輱輲 InitialValues reference ; 輱輳 void printinitiavalues (){ 輱輴 print (" Data type initial values "); 輱輵 print (" boolean "+t); 輱輶 print (" char "+c); 輱輷 print (" int "+i); 輱輸 print (" long "+l); 輱輹 print (" float "+f); 輲輰 print (" double "+d); 輲輱 print (" InitialValues "+ reference ); 輲輲 輲輳 public static void main ( String [] args ){ 輲輴 InitialValues iv = new InitialValues (); 輲輵 iv. printinitiavalues (); 輲輶 輲輷 輲輸 其输出为 : Data type initial values boolean false char [ ] int 0 long 0 float 0.0 double 0.0 InitialValues null char 的初始值是輰, 打印出来是一个空格 另外需要注意的是 : 如果在 class 中定义了一个对象而没有为其赋初值, 则这个对象的 reference 会被赋值 null 8 初始化顺序 在 Java 中, 类变量的初始化先于类方法调用 什么意思? 就是说 : 在写代 码的时候, 即便你把类变量的定义放在了构造函数的后面, Java 依然会先初 始化这些变量, 然后再去调用函数 ( 这个函数通常是构造函数 ) 看代码 : 輱 import static net. mindview. util. Print.*; 輲 class Window { 輳 Window ( int marker ){ 輱輱輯輲輵

12 輴 print (" Window number : " + marker ); 輵 輶 輷 class House { 輸 Window w1 = new Window (1); 輹 House (){ 輱輰 print (" House ()"); 輱輱 w3 = new Window (33); 輱輲 輱輳 Window w2 = new Window (2); 輱輴 void f (){ 輱輵 print ("f()"); 輱輶 輱輷 Window w3 = new Window (3); 輱輸 輱輹 public class OrderOfInitialization 輲輰 { 輲輱 public static void main ( String args []) 輲輲 { 輲輳 House h = new House (); 輲輴 h.f (); 輲輵 輲輶 输出为 : Window number: 1 Window number: 2 Window number: 3 House() Window number: 33 f() 輹 STATIC 类型的初始化 从代码中我们可以看到, House 的构造函数在 w1 和 w2 之间 但是我们执 行 House h = new House() 这一行代码时, 初始化的执行顺序是 : 輱輮初始化 w1 輲輮初始化 w2 輳輮初始化 w3 輴輮调用 House() 对 w3 再次初始化 9 static 类型的初始化 无论创建了多少个对象, static 类型的数据都只占用一份存储 只有 輱輲輯輲輵

13 輹 STATIC 类型的初始化 class 的域可以是 static, 一个本地变量不能是 static 类型的 接下来我们 通过一个例子来查看 static 是如何初始化的輬看代码輺 輱 // specifying initial values in a class definition 輲 import static net. mindview. util. Print.*; 輳輴 class Bowl { 輵 Bowl ( int marker ){ 輶 print (" Bowl (" + marker + ")"); 輷 輸 void f1(int marker ){ 輹 print ("f1(" + marker + ")"); 輱輰 輱輱 輱輲輱輳 class Table { 輱輴 static Bowl bowl = new Bowl (1); 輱輵 Table (){ 輱輶 print (" Table ()"); 輱輷 bowl2.f1 (1); 輱輸 輱輹 void f2(int marker ){ 輲輰 print ("f2(" + marker + ")"); 輲輱 輲輲 static Bowl bowl2 = new Bowl (2); 輲輳 輲輴輲輵 class Cupboard { 輲輶 Bowl bowl3 = new Bowl (3); 輲輷 static Bowl bowl4 = new Bowl (4); 輲輸 Cupboard (){ 輲輹 print (" Cupboard ()"); 輳輰 bowl4.f1 (2); 輳輱 輳輲 void f3(int marker ){ 輳輳 print ("f3(" + marker + ")"); 輳輴 輳輵 static Bowl bowl5 = new Bowl (5); 輳輶 輳輷 public class StaticInitialization 輳輸 { 輳輹 public static void main ( String args []) 輴輰 { 輴輱 print (" Creating new Cupboard () in main "); 輴輲 new Cupboard (); 輴輳 print (" Creating new Cupboard () in main "); 輴輴 new Cupboard (); 輴輵 table.f2 (1); 輴輶 cupboard.f3 (1); 輴輷 輴輸 static Table table = new Table (); 輴輹 static Cupboard cupboard = new Cupboard (); 輵輰 这段代码是我目前敲过的最长的轊轡轶轡代码, 其输出也最长, 看输出輺 輱輳輯輲輵

14 Bowl(1) Bowl(2) Table() f1(1) Bowl(4) Bowl(5) Bowl(3) Cupboard() f1(2) Creating new Cupboard() in main Bowl(3) Cupboard() f1(2) Creating new Cupboard() in main Bowl(3) Cupboard() f1(2) f2(1) f3(1) 輹 STATIC 类型的初始化 让我们来仔细分析一下每一行的输出是怎么来的 通过 Bowl 我们可以知道初始化的顺序 当我们调用 main() 时, 首先初始化的是 StaticInitialization 中的 static 成员, 然后是 non-static 成员 在这个代码中是先初始化最后两行的 table 和 cupboard 在初始化 table 过程中, 生成了前四行输出 具体过程是 : 先初始化 Table 的 bowl1 和 bowl(2) 然后调用构造函数 Table() 生成第三行第四行输出 在初始化 cupboard 过程中, 生成了接下来的五行输出 具体过程是 : 先初始化 bowl(4) 和 bowl(5) 然后初始化 bowl3 最后调用 Cupboard() 构造函数 table 和 cupboard 初始化结束后, 接下来执行第輴輱行打印了一句提示, 然后执行第輴輲行, 这个时候由于 bowl4 和 bowl5 已经被初始化了, 所以只初始化了 bowl3 并调用了 Cupboard() 构造函数 然后执行第輴輳行, 同样的只初始化了 bowl3 并调用了 Cupboard() 构造函数 輱輴輯輲輵

15 最后调用 table.f2(2) 和 cupboard.f3(1) 生成最后两行输出 輱輰 显示初始化 10 显示初始化 在 Java 中可以使用 static 语句初始化 ( 有时候我们叫之中初始化方式为 static 块 ) 看代码 : 輱 public class Spoon { 輲 static int i; 輳 static { 輴 i = 47; 輵 輶 看起来像是一个方法, 但是注意这种初始化方法仅仅是一个 static 关键词跟 着一个语句块 同其他 static 初始化语句一样, 使用 static 块的初始化也仅 仅执行一次 看代码 : 輱 class Cup { 輲 Cup ( int marker ){ 輳 print (" Cup (" + marker + ")"); 輴 輵 void f( int marker ){ 輶 print ("f(" + marker + ")"); 輷 輸 輹輱輰 class Cups { 輱輱 static Cup cup1 ; 輱輲 static Cup cup2 ; 輱輳 static { 輱輴 cup1 = new Cup (1); 輱輵 cup2 = new Cup (2); 輱輶 輱輷 Cups (){ 輱輸 print (" Cups ()"); 輱輹 輲輰 輲輱輲輲 public class ExplicitStatic { 輲輳 public static void main ( String [] args ){ 輲輴 print (" Inside main ()"); 輲輵 Cups. cup1.f (99); ( cupsrun ) 輲輶 輲輷 static Cups cups1 = new Cups (); ( cupsrun1 ) 輲輸 输出为 : Inside main() 輱輵輯輲輵

16 Cup(1) Cup(2) f(99) 輱輰 显示初始化 static 初始化语句在下列任一情况下初始化 Cups : 輱輮第轣轵轰轳轲轵轮行执行 輲輮第轣轵轰轳轲轵轮被注释, 第轣轵轰轳轲轵轮輱行解注 ; 在情况輱, 我们访问了 Cups 的成员变量, 这个时候出发了 Cups 类的初始化 ; 在情况輲, 我们初始化了对象 cups1 当我们把第轣轵轰轳轲轵轮輱行解注, 第轣轵轰轳轲轵轮注释掉之后, 输出为 : Cup(1) Cup(2) Cups() Inside main() 可以看到在类 ExplicitStatic 中, 也是 static 变量先初始化 我们看到 Inside main() 最后输出 说明程序先完成了静态成员 cups1 的初始化之后再调用的 main 函数 如果我把第轣轵轰轳轲轵轮輱行和第轣轵轰轳轲轵轮行都解注, 则输出 : Cup(1) Cup(2) Cups() Inside main() f(99) 可以看出还是 static 变量优先, 通过第轣轵轰轳轲轵轮輱行对 Cups 类的静态变量进行了初始化 然后再执行 main 函数 问题 Create a class with a static String field that is initialized at the point of definition, and another one that is initialized by the static block. Add a static method that prints both fields and demonstrates that they are both initialized before they are used. 解答 : 首先编写代码, 如下 輱輶輯輲輵

17 輱輰 显示初始化 輱 import static net. mindview. util. Print.*; 輲輳 class String1 { 輴 static String str1 = " string in String1 "; 輵 String1 (){ 輶 print ("" + str1 ); 輷 輸 輹 class String2 { 輱輰 static String str2 ; 輱輱 static { 輱輲 str2 = " string in string2 "; 輱輳 輱輴 String2 (){ 輱輵 print ("" + str2 ); 輱輶 輱輷 輱輸輱輹 public class Exercise0614 { 輲輰 public static void main ( String [] args ){ 輲輱 print (" Inside main ()"); 輲輲 String1 str1 = new String1 (); 輲輳 String2 str2 = new String2 (); 輲輴 輲輵 输出为 : Inside main() string in String1 string in string2 之所以按顺序初始化 str1 和 str2, 是因为在 Exercise0614 的类中, 这两个 变量不是 static, 把这两个类改成 static 的有 : 輱 import static net. mindview. util. Print.*; 輲輳 class String1 { 輴 static String str1 = " string in String1 "; 輵 String1 (){ 輶 print ("" + str1 ); 輷 輸 輹 class String2 { 輱輰 static String str2 ; 輱輱 static { 輱輲 str2 = " string in string2 "; 輱輳 輱輴 String2 (){ 輱輵 print ("" + str2 ); 輱輶 輱輷 輱輷輯輲輵

18 輱輸輱輹 public class Exercise0614 { 輲輰 public static void main ( String [] args ){ 輲輱 print (" Inside main ()"); 輲輲 輲輳 static String1 str1 = new String1 (); 輲輴 static String2 str2 = new String2 (); 輲輵 輲輶 輱輰 显示初始化 输出为 : string in String1 string in string2 Inside main() 然后修改代码, 为其添加静态函数 ( 静态函数可以在不定义对象的时候调 用, 而我们调用静态函数的同时, 对这个静态函数所属的类初始化, 主要是初 始化其 static 变量 ) 輱 import static net. mindview. util. Print.*; 輲輳 class String1 { 輴 static String str1 = " string in String1 "; 輵 String1 (){ 輶 print (" construct 1" + str1 ); 輷 輸 static void f1 (){ 輹 print (" static method " + str1 ); 輱輰 輱輱 輱輲 class String2 { 輱輳 static String str2 ; 輱輴 static { 輱輵 str2 = " string in string2 "; 輱輶 輱輷 String2 (){ 輱輸 print (" constructor 2" + str2 ); 輱輹 輲輰 static void f2 (){ 輲輱 print (" static method " + str2 ); 輲輲 輲輳 輲輴輲輵 public class Exercise0614 { 輲輶 public static void main ( String [] args ){ 輲輷 print (" Inside main ()"); 輲輸 String2.f2 (); 輲輹 String1.f1 (); 輳輰 輳輱 static String2 str2 = new String2 (); 輳輲 輱輸輯輲輵

19 输出为 : constructor 2string in string2 Inside main() static methodstring in string2 static methodstring in String1 輱輱 非静态实例初始化 11 非静态实例初始化 对于非静态变量, 轪轡轶轡提供了类似于 static 块的初始化方式 看代码 : 輱 import static net. mindview. util. Print.*; 輲輳 class Mug { 輴 Mug ( int marker ){ 輵 print (" Mug (" + marker +")"); 輶 輷 void f( int marker ){ 輸 print ("f(" + marker + ")"); 輹 輱輰 輱輱 public class Mugs { 輱輲 Mug mug1 ; 輱輳 Mug mug2 ; 輱輴 { 輱輵 mug1 = new Mug (1); 輱輶 mug2 = new Mug (2); 輱輷 print (" mug1 & mug2 initialized "); 輱輸 輱輹 Mugs (){ 輲輰 print (" Mugs ()"); 輲輱 輲輲 Mugs ( int i){ 輲輳 print (" Mugs ( int )"); 輲輴 輲輵 public static void main ( String [] args ){ 輲輶 print (" Inside main ()"); 輲輷 new Mugs (); 輲輸 print (" new Mugs () completed "); 輲輹 new Mugs (1); 輳輰 print (" new Mugs (1) completed "); 輳輱 輳輲 输出为 : Inside main() Mug(1) Mug(2) 輱輹輯輲輵

20 mug1 & mug2 initialized Mugs() new Mugs() completed Mug(1) Mug(2) mug1 & mug2 initialized Mugs(int) new Mugs(1) completed 輱輲 数组初始化 从这个输出可以看出, 实例可以按照顺序初始化, 没有像 static 一样执行顺 序和代码出现顺序不一样的情况 12 数组初始化 数组是一些相同类型元素的集合 这些元素可以是基础类型也可以是某个 类 ( 这么说可能有些不严谨, 基础类型也是类, 在轊轡轶轡中一切都是类 ) 定义一个整型数组可以使用 int[] a1; 也可以用 int a1[] 在 Java 中, 数组的初始化可以通过大括号实现, 也可以不初始化 Java 中, 数组名的赋 值, 复制的是引用 看代码 : 輱 import static net. mindview. util. Print.*; 輲輳 public class ArrayOfPrimitives { 輴 public static void main ( String [] args ){ 輵 int [] a1 = {1,2,3,4,5; 輶 int [] a2; 輷 a2 = a1; 輸 for ( int i = 0; i < a1. length ; i ++) { 輹 a2[i] = a2[i ]*2; 輱輰 輱輱 for ( int i = 0; i < a1. length ; i ++) { 輱輲 print ("a1[" + i + "]= " + a1[i ]); 輱輳 輱輴 輱輵 输出是 : a1[0]= 2 a1[1]= 4 a1[2]= 6 a1[3]= 8 輲輰輯輲輵

21 a1[4]= 10 輱輲 数组初始化 可以看到执行了 a2=a1 之后, a2 指向的内容和 a1 指向的内容是一样的 这时 候即使对 a2 进行修改, a1 的内容也同时发生了改变 关于数组越界的问题在 C/C++ 和 Java 中有不同的处理方法 : C/C++ 不会 对数组越界进行约束, 而 Java 会 在 Java 中, 一旦数组越界就会报错 虽然 适时的检查会不会报错是一件很低效的事情, 但是为了开发效率, Java 的设 计者认为这是值得的 对于事先不知道长度的数组, 需要用 new 来为其分配空间, 看代码 : 輱 import java. util.*; 輲 import static net. mindview. util. Print.*; 輳輴 public class ArrayNew { 輵 public static void main ( String [] args ){ 輶 int [] a; 輷 Random rand = new Random (47); 輸 a = new int [ rand. nextint (20)]; 輹 print (" length of a = " + a. length ); 輱輰 print ( Arrays. tostring (a )); 輱輱 輱輲 输出为 : length of a = 18 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 之前创建了 primitive 的数组 现在创建对象数组, 当创建对象数组时, 数组元素是对象的索引 现在考虑创建 Integer 数组 ( 回忆一下 Integer 是 类不是轰轲轩轭轩轴轩轶轥类型 基础类型和类的区别是, 基础类型保存在栈上, 而对象 保存在堆上 ) 輱 import java. util.*; 輲 import static net. mindview. util. Print.*; 輳輴 public class ArrayClassObj { 輵 public static void main ( String [] args ){ 輶 Random rand = new Random (47); 輷 Integer [] a = new Integer [ rand. nextint (10)]; 輸 print ( Arrays. tostring (a )); 輹 print (" length of a = " + a. length ); 輱輰 for ( int i = 0; i < a. length ; i ++) { 輱輱 a[i] = rand. nextint (500); 輱輲 輱輳 print ( Arrays. tostring (a )); 輱輴 輲輱輯輲輵

22 輱輵 輱輲 数组初始化 输出是 : [null, null, null, null, null, null, null, null] length of a = 8 [55, 193, 361, 461, 429, 368, 200, 22] 从代码可以看出, 没有初始化之前打印输出的都是 null 而不是像基础类型那 样初始化为 0, 只有初始化之后才会有数据打印 在创建对象数组时, 即使使 用 new 也没有初始化这个数组, 必须一个一个来 对于对象数组也可以用大括号进行初始化, 看代码 : 輱 import java. util.*; 輲 輳 public class ArrayInit { 輴 public static void main ( String [] args ){ 輵 Integer [] a = { 輶 new Integer (1), 輷 new Integer (2), 輸 3, 輹 ; 輱輰 Integer [] b = new Integer []{ 輱輱 new Integer (1), 輱輲 new Integer (2), 輱輳 3, 輱輴 ; 輱輵 System. out. println ( Arrays. tostring (a )); 輱輶 System. out. println ( Arrays. tostring (b )); 輱輷 輱輸 输出为 : [1, 2, 3] [1, 2, 3] 注意初始化对象数组时, 最后一个元素后面的逗号 使用这个逗号写出的 代码便于维护, 尤其是维护长数组 可以用这种初始化方法传递变长参数 看 代码 : 輱 class A{ 輲輳 public class VarArgs { 輴 static void printarray ( Object [] args ){ 輵 for ( Object obj : args ) 輶 System. out. print ( obj + " "); 輷 System. out. println (); 輲輲輯輲輵

23 輱輲 数组初始化 輸 輹 public static void main ( String [] args ){ 輱輰 printarray ( new Object []{ 輱輱 new Integer (47), new Float (3.14), new Double (11.11), 輱輲 ); 輱輳 printarray ( new Object []{ " one "," two "," three " ); 輱輴 printarray ( new Object []{ new A(), new A(), new A ()); 輱輵 輱輶 输出是 : one two three A@15db9742 A@6d06d69c A@7852e922 上面代码的 Object 共有的根类, 关于这个类, 我们后面还会学到更多 因为 所有类都是从 Object 继承而来, 所以可以把 Object 数组传入一个方法 另外我们还可以看到,print 函数接收一个 Object 的数组, 然后用 foreach 的循环语法打印每个 Object 数组中 reference 对应的内容 打印标准的 Java 库类输出具有较强的可读性 ( 看输出的前两行 ), 打印自定义的类的输出 ( 输出 的第三行 ) 就有点不知所云 不过从输出的第三行可以看出打印自定义类, 其 输出具有固定的格式, 然后是一串十六进制数 ( 以后我们会了 解到, 这串十六进制数是对象地址 ) 上面的这段代码在轊轡轶轡轓轅輵之前比较常见, 但是自从轊轡轶轡轓轅輵之后, 就有 更方便的写法了 : 可以像 printarray() 那样打印数组 ( 我现在写这个笔记的 时候用的是轓轅輸, 所以浪费了一段时间学习了一个历史技术 ) 看代码 : 輱 public class NewVarArgs { 輲 static void printarray ( Object... args ){ 輳 for ( Object obj : args ) { 輴 System. out. print ( obj + " "); 輵 輶 System. out. println (); 輷 輸 public static void main ( String [] args ){ 輹 printarray ( new Integer (47), new Float (3.14), new Double (11.11)); 輱輰 printarray (47,3.14F,11.11); 輱輱 printarray (" one "," two "," three "); 輱輲 printarray ( new A(), new A(), new A ()); 輱輳 printarray (( Object []) new Integer []{1,2,3,4); ( NewVarArgsline2 ) 輱輴 printarray (); // Empth list is also OK; 輱輵 輱輶 輲輳輯輲輵

24 输出为 : 輱輲 数组初始化 one two three A@15db9742 A@6d06d69c A@7852e 开心的服下这颗语法糖 当你使用 varargs 时, 不在需要写明数组信息, 编译器会自动帮你填写 编译器会给 print() 函数一个 array 但是注意这里不仅仅是从一个元素列 表到一个数组的转换 注意代码中第轎轥轷轖轡轲轁轲轧轳转轩轮轥輲行, 我们可以看到一个 Integer 数组转换成了一个 Object 数组 在编译过程中, 编译器看到这是一 个数组, 并不会做转换 ( 对这句话我还没有深刻的理解, 需要以后回头看 ) 最后一行代码告诉我们, 可以对一个 vararg 的列表传送零个参数 这个 语法很有用, 尤其是当函数的尾随参数个数可变时 关于尾随参数, 看代码 : 輱 public class OptionalTrailingArguments { 輲 static void f( int required, String... trailing ){ 輳 System. out. print (" required : " + required + " "); 輴 輵 for ( String s: trailing ) 輶 System. out. print (s + " "); 輷 System. out. println (); 輸 輹 public static void main ( String [] args ){ 輱輰 f(1," one "); 輱輱 f(2," two "," three "); 輱輲 f (0); 輱輳 輱輴 输出为 : required: 1 one required: 2 two three required: 0 从上面代码还可以看出, 可以使用除了 Object 之外的类型作为 varargs 的类型 ( 在这里例子中, 我们实用的是 String ) 事实上, 可以使用任何类型 作为可变参数类型 看代码 : 輱 public class VarargType { 輲輴輯輲輵

25 輱輲 数组初始化 輲 static void f( Character... args ){ 輳 System. out. print ( args. getclass ()); 輴 System. out. println (" length " + args. length ); 輵 輶 static void g( int... args ){ 輷 System. out. print ( args. getclass ()); 輸 System. out. println (" length " + args. length ); 輹 輱輰 public static void main ( String [] args ){ 輱輱 f( a ); 輱輲 f (); 輱輳 g (1); 輱輴 g (); 輱輵 System. out. println (" int []: " + new int [0]. getclass ()); 輱輶 輱輷 输出为 : class [Ljava.lang.Character; length 1 class [Ljava.lang.Character; length 0 class [I length 1 class [I length 0 int []: class [I 从上面的代码可以看出, 可以使用 Character 数组作为可变参数类型, 也可以使用 int 这种基础类型作为可变参数类型 getclass() 函数是 Object 的内置函数 輲輵輯輲輵

2015 3 3 4 5 148

2015 3 3 4 5 148 1 Q 2 Q Q 147 2015 3 3 4 5 148 6 7 8 Q Q Q Q Q Q Q Q Q / Q 149 2015 3 Q Q Q Q 9 Q 150 10 Q Q Q 輥 輯 訛 Q 輥 輰 訛 輥 輱 訛 Q 151 2015 3 輥 輲 訛 152 Q,,,,, ;,,,,, Q,, 輥 輳 訛 Q 153 2015 3 輥 輴 訛 輥 輵 訛 輥 輶 訛 Q Q Q 154

More information

Southern Cultural Forum

Southern Cultural Forum Southern Cultural Forum 輥 輯 訛 輥 輱 訛 輥 輲 訛 輥 輳 訛 輥 輴 訛 輥 輵 訛 輥 輶 訛 輥 輷 訛 輥 輰 訛 Southern Cultural Forum 輦 輮 訛 輦 輯 訛 輦 輰 訛 輦 輱 訛 輦 輲 訛 輦 輳 訛 輦 輴 訛 輦 輵 訛 輦 輶 訛 輦 輷 訛 輧 輲 訛 輧 輳 訛 輧 輮 訛 輧 輯 訛 輧 輰 訛 輧 輴 訛 輧 輵

More information

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

OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 4 月 18 日晚 9 点 关于抄袭 没有分数 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double

More information

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

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 4 月 19 日晚 9 点 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double x) { d

More information

无类继承.key

无类继承.key 无类继承 JavaScript 面向对象的根基 周爱 民 / aimingoo aiming@gmail.com https://aimingoo.github.io https://github.com/aimingoo rand = new Person("Rand McKinnon",... https://docs.oracle.com/cd/e19957-01/816-6408-10/object.htm#1193255

More information

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

エスポラージュ株式会社 住所 : 東京都江東区大島 東急ドエルアルス大島 HP:  ******************* * 关于 Java 测试试题 ****** ******************* * 关于 Java 测试试题 ******************* 問 1 运行下面的程序, 选出一个正确的运行结果 public class Sample { public static void main(string[] args) { int[] test = { 1, 2, 3, 4, 5 ; for(int i = 1 ; i System.out.print(test[i]);

More information

新・解きながら学ぶJava

新・解きながら学ぶJava 481! 41, 74!= 40, 270 " 4 % 23, 25 %% 121 %c 425 %d 121 %o 121 %x 121 & 199 && 48 ' 81, 425 ( ) 14, 17 ( ) 128 ( ) 183 * 23 */ 3, 390 ++ 79 ++ 80 += 93 + 22 + 23 + 279 + 14 + 124 + 7, 148, 16 -- 79 --

More information

3.1 num = 3 ch = 'C' 2

3.1 num = 3 ch = 'C' 2 Java 1 3.1 num = 3 ch = 'C' 2 final 3.1 final : final final double PI=3.1415926; 3 3.2 4 int 3.2 (long int) (int) (short int) (byte) short sum; // sum 5 3.2 Java int long num=32967359818l; C:\java\app3_2.java:6:

More information

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

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 复习 类的复用 组合 (composition): has-a 关系 class MyType { public int i; public double d; public char c; public void set(double x) { d =

More information

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

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课 复习 Java 包 创建包 : package 语句, 包结构与目录结构一致 使用包 : import restaurant/ - people/ - Cook.class - Waiter.class - tools/ - Fork.class

More information

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 告别 OJ1 - 参考答案 MASTER 2019 年 月 3 日 1 1 INPUTOUTPUT 1 InputOutput 题目描述 用 cin 输入你的姓名 ( 没有空格 ) 和年龄 ( 整数 ), 并用 cout 输出 输入输出符合以下范例 输入 master 999 输出 I am master, 999 years old. 注意 "," 后面有一个空格,"." 结束,

More information

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

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 References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2

More information

OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料

OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢   学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 Email: 51141201063@ecnu.cn 学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料 OOP with Java Java 类型 引用 不可变类型 对象存储位置 作用域 OOP

More information

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

OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 3 提交时间 3 月 29 日晚 9 点 Piazza Project 2 投票 复习 创建对象 构造函数 函数重载 : 函数 = 函数名 + 参数列表 public class MyType { int i; double d; char c; void set(double x)

More information

Microsoft Word - 新1-12.doc

Microsoft Word - 新1-12.doc 实训 5 面向对象编程练习 实训 5 面向对象编程练习 5.1 实训目的 通过编程和上机实验理解 Java 语言是如何体现面向对象编程基本思想 以及如何创建类 和对象 了解成员变量和成员方法的特性 5.2 实训要求 编写一个体现面向对象思想的程序 编写一个创建对象和使用对象的方法的程序 5.3 实训内容 5.3.1 创建对象并使用对象 1 定义一个 Person 类 可以在应用程序中使用该类 成员属性

More information

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

SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 odps-sdk 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基 开放数据处理服务 ODPS SDK SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 "odps-sdk" 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基础功能的主体接口, 搜索关键词 "odpssdk-core" 一些

More information

Microsoft Word - 第3章.doc

Microsoft Word - 第3章.doc Java C++ Pascal C# C# if if if for while do while foreach while do while C# 3.1.1 ; 3-1 ischeck Test() While ischeck while static bool ischeck = true; public static void Test() while (ischeck) ; ischeck

More information

untitled

untitled 1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override

More information

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

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 1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET 2.0 2.0.NET Framework.NET Framework 2.0 ( 3).NET Framework 2.0.NET Framework ( System ) o o o o o o Boxing UnBoxing() o

More information

Microsoft PowerPoint - 8. 运算符重载 Operator Overloading.pptx

Microsoft PowerPoint - 8. 运算符重载 Operator Overloading.pptx 运算符重载 Operator Overloading class Point { public: ; double x_, y_; Why Operator Overloading? Point (double x =0, double y = 0):x_(x),y_(y) { int main(){ Point a(1., 2), b(3,4); Point c = a + b; return 0;

More information

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

KillTest 质量更高 服务更好 学习资料   半年免费更新服务 KillTest 质量更高 服务更好 学习资料 http://www.killtest.cn 半年免费更新服务 Exam : 310-065Big5 Title : Sun Certified Programmer for the Java 2 Platform, SE 6.0 Version : Demo 1 / 14 1. 35. String #name = "Jane Doe"; 36. int

More information

Chapter 9: Objects and Classes

Chapter 9: Objects and Classes 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

More information

OOP with Java 通知 Project 4: 推迟至 4 月 25 日晚 9 点

OOP with Java 通知 Project 4: 推迟至 4 月 25 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 推迟至 4 月 25 日晚 9 点 复习 Protected 可以被子类 / 同一包中的类访问, 不能被其他类访问 弱化的 private 同时赋予 package access class MyType { public int i; public double d; public

More information

EJB-Programming-3.PDF

EJB-Programming-3.PDF :, JBuilder EJB 2.x CMP EJB Relationships JBuilder EJB Test Client EJB EJB Seminar CMP Entity Beans Value Object Design Pattern J2EE Design Patterns Value Object Value Object Factory J2EE EJB Test Client

More information

CHAPTER VC#

CHAPTER VC# 1. 2. 3. 4. CHAPTER 2-1 2-2 2-3 2-4 VC# 2-5 2-6 2-7 2-8 Visual C# 2008 2-1 Visual C# 0~100 (-32768~+32767) 2 4 VC# (Overflow) 2-1 2-2 2-1 2-1.1 2-1 1 10 10!(1 10) 2-3 Visual C# 2008 10! 32767 short( )

More information

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

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0, http://debut.cis.nctu.edu.tw/~chi Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0, : POSITIVE_INFINITY NEGATIVE_INFINITY

More information

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

Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream Class java.io.datainptstream (extends) FilterInputStream InputStream Obj Message Transition 5-1 5-2 DataInputStream Class 5-3 DataOutputStream Class 5-4 PrintStream Class 5-5 (Message Transition) (Exercises) Java Access 5-1 Server Client Client Server Server Client 5-2 DataInputStream

More information

20 Abstract In the middle of the 20 th century a big rumor arose and was transmitted far and wide that there existed hairy men and water monsters. Wit

20 Abstract In the middle of the 20 th century a big rumor arose and was transmitted far and wide that there existed hairy men and water monsters. Wit 104 20 Abstract In the middle of the 20 th century a big rumor arose and was transmitted far and wide that there existed hairy men and water monsters. With an introduction to this rumor the author tries

More information

Guava学习之Resources

Guava学习之Resources Resources 提供提供操作 classpath 路径下所有资源的方法 除非另有说明, 否则类中所有方法的参数都不能为 null 虽然有些方法的参数是 URL 类型的, 但是这些方法实现通常不是以 HTTP 完成的 ; 同时这些资源也非 classpath 路径下的 下面两个函数都是根据资源的名称得到其绝对路径, 从函数里面可以看出,Resources 类中的 getresource 函数都是基于

More information

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

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 复习 Java 包 创建包 : package 语句, 包结构与目录结构一致 使用包 : import restaurant/ - people/ - Cook.class - Waiter.class - tools/ - Fork.class - Table.class

More information

Mac Java import com.apple.mrj.*;... public class MyFirstApp extends JFrame implements ActionListener, MRJAboutHandler, MRJQuitHandler {... public MyFirstApp() {... MRJApplicationUtils.registerAboutHandler(this);

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

untitled

untitled 1 7 7.1 7.2 7.3 7.4 7.5 2 7.1 VFT virtual 7.1 3 1 1. 2. public protected public 3. VFT 4. this const volatile 4 2 5. ( ) ( ) 7.1 6. no-static virtual 7.2 7. inline 7.3 5 3 8. this this 9. ( ) ( ) delete

More information

软件工程文档编制

软件工程文档编制 实训抽象类 一 实训目标 掌握抽象类的定义 使用 掌握运行时多态 二 知识点 抽象类的语法格式如下 : public abstract class ClassName abstract void 方法名称 ( 参数 ); // 非抽象方法的实现代码 在使用抽象类时需要注意如下几点 : 1 抽象类不能被实例化, 实例化的工作应该交由它的子类来完成 2 抽象方法必须由子类来进行重写 3 只要包含一个抽象方法的抽象类,

More information

untitled

untitled 1 Outline 料 類 說 Tang, Shih-Hsuan 2006/07/26 ~ 2006/09/02 六 PM 7:00 ~ 9:30 聯 ives.net@gmail.com www.csie.ntu.edu.tw/~r93057/aspnet134 度 C# 力 度 C# Web SQL 料 DataGrid DataList 參 ASP.NET 1.0 C# 例 ASP.NET 立

More information

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

使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款 JAVA 程 序 设 计 ( 肆 ) 徐 东 / 数 学 系 使 用 Java 语 言 模 拟 保 险 箱 容 量 门 板 厚 度 箱 体 厚 度 属 性 锁 具 类 型 开 保 险 箱 关 保 险 箱 动 作 存 取 款 使 用 Java class 代 表 保 险 箱 public class SaveBox 类 名 类 类 体 实 现 封 装 性 使 用 class SaveBox 代 表 保

More information

Microsoft Word - ch04三校.doc

Microsoft Word - ch04三校.doc 4-1 4-1-1 (Object) (State) (Behavior) ( ) ( ) ( method) ( properties) ( functions) 4-2 4-1-2 (Message) ( ) ( ) ( ) A B A ( ) ( ) ( YourCar) ( changegear) ( lowergear) 4-1-3 (Class) (Blueprint) 4-3 changegear

More information

JavaIO.PDF

JavaIO.PDF O u t p u t S t ream j a v a. i o. O u t p u t S t r e a m w r i t e () f l u s h () c l o s e () public abstract void write(int b) throws IOException public void write(byte[] data) throws IOException

More information

OOP with Java 通知 : Project 2 提交时间 : 3 月 15 日晚 9 点

OOP with Java 通知 : Project 2 提交时间 : 3 月 15 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 : Project 2 提交时间 : 3 月 15 日晚 9 点 复习 : Java 类型 基本类型 boolean, char, 封装 (wrappers) 类 (class) 定义 class MyType { int i; double d; 数据 (Fields) char c; void set(double

More information

OOP with Java 通知 : Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢

OOP with Java 通知 : Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 : Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 Email: 51141201063@ecnu.cn 复习 : Java 类型 基本类型 boolean, char, 封装 (wrappers) 类 (class) 定义 class MyType { int i;

More information

OOP with Java 通知 Project 2 提交时间 : 3 月 21 日晚 9 点 作业提交格式 学习使用 文本编辑器 cmd, PowerShell (Windows), terminal(linux, Mac)

OOP with Java 通知 Project 2 提交时间 : 3 月 21 日晚 9 点 作业提交格式 学习使用 文本编辑器 cmd, PowerShell (Windows), terminal(linux, Mac) OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 2 提交时间 : 3 月 21 日晚 9 点 作业提交格式 学习使用 文本编辑器 cmd, PowerShell (Windows), terminal(linux, Mac) 复习 面向对象编程 将实际问题分解成不同的对象 不的对象提供不同的服务 对象之间可以传递消息 例子小李深夜

More information

C/C++ - 函数

C/C++ - 函数 C/C++ Table of contents 1. 2. 3. & 4. 5. 1 2 3 # include # define SIZE 50 int main ( void ) { float list [ SIZE ]; readlist (list, SIZE ); sort (list, SIZE ); average (list, SIZE ); bargragh

More information

Microsoft PowerPoint - 4. 数组和字符串Arrays and Strings.ppt [兼容模式]

Microsoft PowerPoint - 4. 数组和字符串Arrays and Strings.ppt [兼容模式] Arrays and Strings 存储同类型的多个元素 Store multi elements of the same type 数组 (array) 存储固定数目的同类型元素 如整型数组存储的是一组整数, 字符数组存储的是一组字符 数组的大小称为数组的尺度 (dimension). 定义格式 : type arrayname[dimension]; 如声明 4 个元素的整型数组 :intarr[4];

More information

Microsoft PowerPoint - 6. 用户定义类型User-defined Datatypes.ppt [兼容模式]

Microsoft PowerPoint - 6. 用户定义类型User-defined Datatypes.ppt [兼容模式] 用户定义类型 User-defined Datatypes classes and structs 几何向量 (Geometry Vector) 二维平面上的向量由起点和终点构成 每个点包含两个坐标 (x, y), 因此一个向量需要四个实数表示 Start= (0.9,1.5) Start= (0.4,0.8) int main() { double xstart = 0.4; double xend

More information

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

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 4 月 19 日晚 9 点 复习 Protected 可以被子类 / 同一包中的类访问, 不能被其他类访问 弱化的 private 同时赋予 package access class MyType { public int i; public double d; public char

More information

chap07.key

chap07.key #include void two(); void three(); int main() printf("i'm in main.\n"); two(); return 0; void two() printf("i'm in two.\n"); three(); void three() printf("i'm in three.\n"); void, int 标识符逗号分隔,

More information

Kevin J. O Brien Rightful resistance policy based resistance 1 2 2

Kevin J. O Brien Rightful resistance policy based resistance 1 2 2 AbstractAs a result of the shift of the nation s developmental strategythe restriction of ideology and the deficiency of the governing system of pressure petitionbenefit-seeking petition in rural areas

More information

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

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit Tomcat Web JUnit Cactus JUnit Java Cactus JUnit 26.1 JUnit Java JUnit JUnit Java JSP Servlet JUnit Java Erich Gamma Kent Beck xunit JUnit boolean JUnit Java JUnit Java JUnit Java 26.1.1 JUnit JUnit How

More information

untitled

untitled 1 Outline 類别 欄 (1) 類 類 狀 更 易 類 理 若 類 利 來 利 using 來 namespace 類 ; (2) namespace IBM class Notebook namespace Compaq class Notebook 類别 類 來 類 列 欄 (field) (property) (method) (event) 類 例 立 來 車 類 類 立 車 欄 料

More information

02

02 Thinking in C++: Volume One: Introduction to Standard C++, Second Edition & Volume Two: Practical Programming C++ C C++ C++ 3 3 C C class C++ C++ C++ C++ string vector 2.1 interpreter compiler 2.1.1 BASIC

More information

C/C++程序设计 - 字符串与格式化输入/输出

C/C++程序设计 - 字符串与格式化输入/输出 C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int

More information

untitled

untitled How to using M-Power Report API M-Power Report API 力 了 M-Power Report -- Java (Library) M-Power Report API 行 Java M-Power Report M-Power Report API ( 30 ) PDF/HTML/CSV/XLS JPEG/PNG/SVG 料 料 OutputStream

More information

1 4 1.1 4 1.2..4 2..4 2.1..4 3.4 3.1 Java.5 3.1.1..5 3.1.2 5 3.1.3 6 4.6 4.1 6 4.2.6 5 7 5.1..8 5.1.1 8 5.1.2..8 5.1.3..8 5.1.4..9 5.2..9 6.10 6.1.10

1 4 1.1 4 1.2..4 2..4 2.1..4 3.4 3.1 Java.5 3.1.1..5 3.1.2 5 3.1.3 6 4.6 4.1 6 4.2.6 5 7 5.1..8 5.1.1 8 5.1.2..8 5.1.3..8 5.1.4..9 5.2..9 6.10 6.1.10 Java V1.0.1 2007 4 10 1 4 1.1 4 1.2..4 2..4 2.1..4 3.4 3.1 Java.5 3.1.1..5 3.1.2 5 3.1.3 6 4.6 4.1 6 4.2.6 5 7 5.1..8 5.1.1 8 5.1.2..8 5.1.3..8 5.1.4..9 5.2..9 6.10 6.1.10 6.2.10 6.3..10 6.4 11 7.12 7.1

More information

Microsoft PowerPoint - L17_Inheritance_v4.pptx

Microsoft PowerPoint - L17_Inheritance_v4.pptx C++ Programming Lecture 17 Wei Liu ( 刘 威 ) Dept. of Electronics and Information Eng. Huazhong University of Science and Technology May. 2015 Lecture 17 Chapter 20. Object-Oriented Programming: Inheritance

More information

chp6.ppt

chp6.ppt Java 软 件 设 计 基 础 6. 异 常 处 理 编 程 时 会 遇 到 如 下 三 种 错 误 : 语 法 错 误 (syntax error) 没 有 遵 循 语 言 的 规 则, 出 现 语 法 格 式 上 的 错 误, 可 被 编 译 器 发 现 并 易 于 纠 正 ; 逻 辑 错 误 (logic error) 即 我 们 常 说 的 bug, 意 指 编 写 的 代 码 在 执 行

More information

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

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌 语 言 程 序 设 计 郑 莉 胡 家 威 编 著 清 华 大 学 逸 夫 图 书 馆 北 京 内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌 握 语

More information

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc 2 5 8 11 0 13 1. 13 2. 15 3. 18 1 23 1. 23 2. 26 3. 28 2 36 1. 36 2. 39 3. 42 4. 44 5. 49 6. 51 3 57 1. 57 2. 60 3. 64 4. 66 5. 70 6. 75 7. 83 8. 85 9. 88 10. 98 11. 103 12. 108 13. 112 4 115 1. 115 2.

More information

1 下列类头定义中, 正确的是 面向对象程序设计网络课程 A class x { } B public x extends y { } C public class x extends y {.} D class x extends y implements y1 { } 2 现有两个类 A B,

1 下列类头定义中, 正确的是 面向对象程序设计网络课程 A class x { } B public x extends y { } C public class x extends y {.} D class x extends y implements y1 { } 2 现有两个类 A B, 1 下列类头定义中, 正确的是 A class x B public x extends y C public class x extends y. D class x extends y implements y1 2 现有两个类 A B, 以下描述中表示 B 继承自 A 的是 (D ) A) class A extends B B) class B implements A C) class A

More information

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

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 OOP with Java Yuanbin Wu cs@ecnu OOP with Java 通知 Project 4: 5 月 2 日晚 9 点 复习 Protected 可以被子类 / 同一包中的类访问, 不能被其他类访问 弱化的 private 同时赋予 package access class MyType { public int i; public double d; public char

More information

CHAPTER 1

CHAPTER 1 CHAPTER 1 1-1 System Development Life Cycle; SDLC SDLC Waterfall Model Shelly 1995 1. Preliminary Investigation 2. System Analysis 3. System Design 4. System Development 5. System Implementation and Evaluation

More information

1 1 大概思路 创建 WebAPI 创建 CrossMainController 并编写 Nuget 安装 microsoft.aspnet.webapi.cors 跨域设置路由 编写 Jquery EasyUI 界面 运行效果 2 创建 WebAPI 创建 WebAPI, 新建 -> 项目 ->

1 1 大概思路 创建 WebAPI 创建 CrossMainController 并编写 Nuget 安装 microsoft.aspnet.webapi.cors 跨域设置路由 编写 Jquery EasyUI 界面 运行效果 2 创建 WebAPI 创建 WebAPI, 新建 -> 项目 -> 目录 1 大概思路... 1 2 创建 WebAPI... 1 3 创建 CrossMainController 并编写... 1 4 Nuget 安装 microsoft.aspnet.webapi.cors... 4 5 跨域设置路由... 4 6 编写 Jquery EasyUI 界面... 5 7 运行效果... 7 8 总结... 7 1 1 大概思路 创建 WebAPI 创建 CrossMainController

More information

帝国CMS下在PHP文件中调用数据库类执行SQL语句实例

帝国CMS下在PHP文件中调用数据库类执行SQL语句实例 帝国 CMS 下在 PHP 文件中调用数据库类执行 SQL 语句实例 这篇文章主要介绍了帝国 CMS 下在 PHP 文件中调用数据库类执行 SQL 语句实例, 本文还详细介绍了帝国 CMS 数据库类中的一些常用方法, 需要的朋友可以参考下 例 1: 连接 MYSQL 数据库例子 (a.php)

More information

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

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 25 9 2008 9 M ICROEL ECTRON ICS & COMPU TER Vol. 25 No. 9 September 2008 J ava 1,2, 1,2, 1,2 (1, 330022 ; 2, 330022) :,. Apla - Java,,.. : PAR ;Apla - Java ; ;CMP ; : TP311 : A : 1000-7180 (2008) 09-0018

More information

2 3 4 5 118 2009/06

2 3 4 5 118 2009/06 * [ / ] [ ] Abstract The rites of repentance in the folk society of Putian in Fujian are a ceremony held by rich families to reward deities for wish fulfillment and are therefore religious rites of a private

More information

通过Hive将数据写入到ElasticSearch

通过Hive将数据写入到ElasticSearch 我在 使用 Hive 读取 ElasticSearch 中的数据 文章中介绍了如何使用 Hive 读取 ElasticSearch 中的数据, 本文将接着上文继续介绍如何使用 Hive 将数据写入到 ElasticSearch 中 在使用前同样需要加入 elasticsearch-hadoop-2.3.4.jar 依赖, 具体请参见前文介绍 我们先在 Hive 里面建个名为 iteblog 的表,

More information

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 WWW PHP 2003 1 Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2 Comments PHP Shell Style: # C++ Style: // C Style: /* */ $value = $p * exp($r * $t); # $value

More information

C++ 程序设计 告别 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 告别 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 告别 OJ2 - 参考答案 MASTER 2019 年 5 月 3 日 1 1 TEMPLATE 1 Template 描述 使用模板函数求最大值 使用如下 main 函数对程序进行测试 int main() { double a, b; cin >> a >> b; cout c >> d; cout

More information

EJB-Programming-4-cn.doc

EJB-Programming-4-cn.doc EJB (4) : (Entity Bean Value Object ) JBuilder EJB 2.x CMP EJB Relationships JBuilder EJB Test Client EJB EJB Seminar CMP Entity Beans Session Bean J2EE Session Façade Design Pattern Session Bean Session

More information

《大话设计模式》第一章

《大话设计模式》第一章 第 1 章 代 码 无 错 就 是 优? 简 单 工 厂 模 式 1.1 面 试 受 挫 小 菜 今 年 计 算 机 专 业 大 四 了, 学 了 不 少 软 件 开 发 方 面 的 东 西, 也 学 着 编 了 些 小 程 序, 踌 躇 满 志, 一 心 要 找 一 个 好 单 位 当 投 递 了 无 数 份 简 历 后, 终 于 收 到 了 一 个 单 位 的 面 试 通 知, 小 菜 欣 喜

More information

Microsoft Word - 01.DOC

Microsoft Word - 01.DOC 第 1 章 JavaScript 简 介 JavaScript 是 NetScape 公 司 为 Navigator 浏 览 器 开 发 的, 是 写 在 HTML 文 件 中 的 一 种 脚 本 语 言, 能 实 现 网 页 内 容 的 交 互 显 示 当 用 户 在 客 户 端 显 示 该 网 页 时, 浏 览 器 就 会 执 行 JavaScript 程 序, 用 户 通 过 交 互 式 的

More information

教案模板4-2

教案模板4-2 传智播客 Java 基础入门 教学设计 课程名称 : Java 基础入门 授课年级 : 2014 年级 授课学期 : 2014 学年第一学期 教师姓名 : 某某老师 2014 年 02 月 09 日 课题名称第 3 章面向对象上 计划学时 6 课时 Java 是一种面向对象的语言, 认识面向对象的编程思想对于 Java 学习至关重 内容分析 要 在面向对象中, 有两个重要的概念, 分别是类和对象,

More information

FY.DOC

FY.DOC 高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主

More information

C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1

C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 C++ 程序设计 OJ1 - 参考答案 MASTER 2019 年 5 月 3 日 1 1 CIRCLE 1 Circle 描述 编写一个圆类 Circle, 实现半径的输入 面积的计算和输出 输入 圆的半径 (double 类型 ) 输出 圆的面积 ( 保留小数点后两位 ) 样例输入 3 样例输出 28.27 提示 圆周率的取值需要比较精确, 以保证计算结果的精度 #include

More information

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

KillTest 质量更高 服务更好 学习资料   半年免费更新服务 KillTest 质量更高 服务更好 学习资料 http://www.killtest.cn 半年免费更新服务 Exam : 70-536Chinese(C++) Title : TS:MS.NET Framework 2.0-Application Develop Foundation Version : DEMO 1 / 10 1. Exception A. Data B. Message C.

More information

untitled

untitled 1 MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/ Object object 參 類 都 object 參 object Boxing 參 boxing

More information

untitled

untitled 1 Outline ArrayList 類 列類 串類 類 類 例 理 MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/ Object object

More information

C/C++ - 文件IO

C/C++ - 文件IO C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;

More information

javaexample-02.pdf

javaexample-02.pdf n e w. s t a t i c s t a t i c 3 1 3 2 p u b l i c p r i v a t e p r o t e c t e d j a v a. l a n g. O b j e c t O b j e c t Rect R e c t x 1 y 1 x 2 y 2 R e c t t o S t r i n g ( ) j a v a. l a n g. O

More information

Microsoft PowerPoint - string_kruse [兼容模式]

Microsoft PowerPoint - string_kruse [兼容模式] Strings Strings in C not encapsulated Every C-string has type char *. Hence, a C-string references an address in memory, the first of a contiguous set of bytes that store the characters making up the string.

More information

JAVA String常用APi

JAVA String常用APi JAVA String 常 用API 2015 年 5 月13 日 星 期 三 ------------------------------------------ String 类 的 特 点 : 字 符 串 对 象 一 旦 被 初 始 化 就 不 会 被 改 变 abc 存 储 在 字 符 串 常 量 池 中 Java 的 核 心 类 包 是 java.lang eclipse:ctrl+ 方

More information

第3章.doc

第3章.doc 3 3 3 3.1 3 IT Trend C++ Java SAP Advantech ERPCRM C++ C++ Synopsys C++ NEC C C++PHP C++Java C++Java VIA C++ 3COM C++ SPSS C++ Sybase C++LinuxUNIX Motorola C++ IBM C++Java Oracle Java HP C++ C++ Yahoo

More information

<4D F736F F F696E74202D20B5DA3032BDB25FC0E0BACDB6D4CFF3312E BBCE6C8DDC4A3CABD5D>

<4D F736F F F696E74202D20B5DA3032BDB25FC0E0BACDB6D4CFF3312E BBCE6C8DDC4A3CABD5D> 程序设计实习 (I): C++ 程序设计 第二讲类和对象 (1) 面向对象的程序设计 面向对象的程序设计方法, 能够较好解决结构化程序设计中出现的问题 面向对象的程序 = 类 + 类 + + 类 设计程序的过程, 就是设计类的过程 2 面向对象的程序设计 面向对象的程序设计方法 : 将某类客观事物共同特点 ( 属性 ) 归纳出来, 形成一个数据结 构 ( 可以用多个变量描述事物的属性 ); 将这类事物所能进行的行为也归纳出来,

More information

c_cpp

c_cpp C C++ C C++ C++ (object oriented) C C++.cpp C C++ C C++ : for (int i=0;i

More information

模板

模板 制作人 : 张刚 目录 类和对象 面向对象程序设计基本特征 类的声明 构造方法 成员变量和方法 封装 继承 多态 包 访问控制 final static 抽象类和接口 内部类 沈阳工业大学软件学院 Java 课程教研组 Page 2 核心知识点 类 对象 三个基本特征 类的基本结构 成员变量 构造方法 成员方法 类实例 对象创建和操作 沈阳工业大学软件学院 Java 课程教研组 Page 3 1.

More information

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc 2 5 8 11 0 1. 13 2. 15 3. 18 1 1. 22 2. 25 3. 27 2 1. 35 2. 38 3. 41 4. 43 5. 48 6. 50 3 1. 56 2. 59 3. 63 4. 65 5. 69 13 22 35 56 6. 74 7. 82 8. 84 9. 87 10. 97 11. 102 12. 107 13. 111 4 114 1. 114 2.

More information

PowerPoint 演示文稿

PowerPoint 演示文稿 The BitCoin Scripting Language 交易实例 交易结构 "result": { "txid": "921a dd24", "hash": "921a dd24", "version": 1, "size": 226, "locktime": 0, "vin": [ ], "vout": [ ], "blockhash": "0000000000000000002c510d

More information

姓名 : 年级专业 : 学号 : 凡年级专业 姓名 学号错写 漏写或字迹不清者, 成绩按零分记 密 封 线 java 较难 试卷 总分 题号 一 二 三 四 五 题分 得分 D 国际通信协议 4 下面选项中, 不是面向对象的特征的是 ( ) A 封装 B 继承 得分 一 单选题 ( 每题 3 分,

姓名 : 年级专业 : 学号 : 凡年级专业 姓名 学号错写 漏写或字迹不清者, 成绩按零分记 密 封 线 java 较难 试卷 总分 题号 一 二 三 四 五 题分 得分 D 国际通信协议 4 下面选项中, 不是面向对象的特征的是 ( ) A 封装 B 继承 得分 一 单选题 ( 每题 3 分, java 较难 试卷 总分 题号 一 二 三 四 五 题分 D 国际通信协议 4 下面选项中, 不是面向对象的特征的是 ( ) A 封装 B 继承 一 单选题 ( 每题 3 分, 共计 15 分 ) 1 下列修饰符中, 成员内部类被 ( ) 修饰后, 可以被外界访问 C 多态 D 重构 5 下列关于构造方法重载的说法中, 错误的是 () A 不同构造方法中调用本类其它的构造方法时, 需要使用 this([

More information

C/C++语言 - C/C++数据

C/C++语言 - C/C++数据 C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;

More information

Microsoft Word - word模板-教师.doc

Microsoft Word - word模板-教师.doc 传智播客 Java 基础入门 教学设计 课程名称 : Java 基础入门 授课年级 : 2014 年级 授课学期 : 2014 学年第一学期 教师姓名 : 某某老师 2014 年 02 月 09 日 课题名称内容分析教学目标及基本要求重点及措施难点及措施 计划第 3 章面向对象上 6 课时学时 Java 是一种面向对象的语言, 认识面向对象的编程思想对于 Java 学习至关重要 在面向对象中, 有两个重要的概念,

More information

Microsoft Word - 第3章.doc

Microsoft Word - 第3章.doc 第 3 章 lambda 表达式及其应用 lambda 表达式是 Java 8 提供的一种新特性, 它使得 Java 也能像 C# 和 C++ 语言一样进行简单的 函数式编程, 这不仅简化了某些通用结构的实现方式, 也大大增强了 Java 语言的表达功能 3.1 lambda 表达式简介 lambda 表达式是基于数学中的 λ 演算得名, 本质上就是一个没有方法名的匿名方法 例如, 有一个方法定义如下

More information

C++ 程式設計

C++ 程式設計 C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004

More information

<4D6963726F736F667420506F776572506F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

<4D6963726F736F667420506F776572506F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074> 程 序 设 计 实 习 INFO130048 3-2.C++ 面 向 对 象 程 序 设 计 重 载 继 承 多 态 和 聚 合 复 旦 大 学 计 算 机 科 学 与 工 程 系 彭 鑫 pengxin@fudan.edu.cn 内 容 摘 要 方 法 重 载 类 的 继 承 对 象 引 用 和 拷 贝 构 造 函 数 虚 函 数 和 多 态 性 类 的 聚 集 复 旦 大 学 计 算 机 科 学

More information

概述

概述 OPC Version 1.6 build 0910 KOSRDK Knight OPC Server Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9 OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOS_Init...5 2.2.2 KOS_InitB...5 2.2.3

More information

没有幻灯片标题

没有幻灯片标题 指针作为函数参数 : 原因 : 1 需要修改一个或多个值,( 用 return 语句不能解决问题 ) 2 执行效率的角度 使用方法 : 在函数原型以及函数首部中需要声明能够接受指针值的形参, 具体的写法为 : 数据类型 * 形参名 如果有多个指针型形参, 则用逗号分隔, 例如 : void swap(int *p1, int *p2) 它说明了形参 p1 p2 是指向整型变量的指针 在函数调用时,

More information

Chapter 9: Objects and Classes

Chapter 9: Objects and Classes Java application Java main applet Web applet Runnable Thread CPU Thread 1 Thread 2 Thread 3 CUP Thread 1 Thread 2 Thread 3 ,,. (new) Thread (runnable) start( ) CPU (running) run ( ) blocked CPU sleep(

More information

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

KillTest 质量更高 服务更好 学习资料   半年免费更新服务 KillTest 质量更高 服务更好 学习资料 http://www.killtest.cn 半年免费更新服务 Exam : 1Z0-854 Title : Java Standard Edition 5 Programmer Certified Professional Upgrade Exam Version : Demo 1 / 12 1.Given: 20. public class CreditCard

More information

untitled

untitled A, 3+A printf( ABCDEF ) 3+ printf( ABCDEF ) 2.1 C++ main main main) * ( ) ( ) [ ].* ->* ()[] [][] ** *& char (f)(int); ( ) (f) (f) f (int) f int char f char f(int) (f) char (*f)(int); (*f) (int) (

More information

untitled

untitled 4.1AOP AOP Aspect-oriented programming AOP 來說 AOP 令 理 Cross-cutting concerns Aspect Weave 理 Spring AOP 來 AOP 念 4.1.1 理 AOP AOP 見 例 來 例 錄 Logging 錄 便 來 例 行 留 錄 import java.util.logging.*; public class HelloSpeaker

More information

新版 明解C++入門編

新版 明解C++入門編 511!... 43, 85!=... 42 "... 118 " "... 337 " "... 8, 290 #... 71 #... 413 #define... 128, 236, 413 #endif... 412 #ifndef... 412 #if... 412 #include... 6, 337 #undef... 413 %... 23, 27 %=... 97 &... 243,

More information