Head First Java第2章练习泳池迷宫
来源:互联网 发布:java multimap 编辑:程序博客网 时间:2024/04/30 22:56
为了输出对比更明显,稍稍更改了下:
1、最后输出e2.count=10代码:
public class EchoTest{public static void main(String[] args){Echo e1=new Echo();Echo e2=new Echo();int x=0;while(x<4){System.out.print("此时x="+x+"\t\t");e1.hello();e1.count=e1.count+1;if(x==3){e2.count=e2.count+1;}if(x>0){e2.count=e2.count+e1.count;}x=x+1;System.out.println("e1.count = "+e1.count+"\te2.count = "+e2.count);}}}class Echo{int count=0;void hello(){System.out.println("helloooooooooooo...");}}结果:
2、最后输出e2.count=24代码:
public class EchoTest{public static void main(String[] args){Echo e1=new Echo();Echo e2=e1;int x=0;while(x<4){System.out.print("此时x="+x+"\t\t");e1.hello();e1.count=e1.count+1;if(x==3){e2.count=e2.count+1;}if(x>0){e2.count=e2.count+e1.count;}x=x+1;System.out.println("e1.count = "+e1.count+"\te2.count = "+e2.count);}}}class Echo{int count=0;void hello(){System.out.println("helloooooooooooo...");}}结果:
3、区别:
改动了e2的声明。
1中e2的声明是Echo e2=new Echo();
2中e2的声明是Echo e2=e1;
- Head First Java第2章练习泳池迷宫
- Head First Java第3章练习“我是编译器”——Hobbits类
- 泳池迷宫
- 泳池迷宫
- 记录-Head first java-第7-8章
- Java Head First 第8章 接口与抽象类
- Head First Java第2章猜数字游戏代码修改
- Head First Java第二章
- Head First JAVA 拾忆-2
- 2016/2/3 Head First Java 第五节/第六节小结
- 2016/2/13 Head First Java 第7节第一部分小结 继承
- 2016/2/13 Head First Java 第7节第二小结 多态
- Head First Java 一 二章
- 记录-Head first java-第四章
- 记录-Head first java-第五章
- Head first java 第五章(一)
- Head first java 第五章(二)
- Head First Java 第三章 变量
- 内存问题
- 数据挖掘之AdaBoost算法
- eclipse代码折叠/展开之笔记本快捷键设置
- 记十年前的暑假
- 广度优先搜索C++练习题HDU 1242 Rescue
- Head First Java第2章练习泳池迷宫
- JNI编程:c++ 调用java 对象
- iOS 关于CGRect
- JTree 的使用
- 古文仿写:桂娘传
- #pragma once 与 #ifndef 解析
- 可移动的菜单栏
- 黑马程序员_正则表达式
- linux下的词典sdcv