重载构造函数(相同运算结果,不同性能比较)
2015-12-20 23:10
323 查看
import java.awt.Point; class Box2 { int x1; int y1; int x2; int y2; Box2(int x,int y,int z,int w) { this.x1 = x; this.y1 = y; this.x2 = z; this.y2 = w; } Box2(Point topleft,Point bottomright) { this(topleft.x,topleft.y,bottomright.x,bottomright.y); } Box2(Point topleft,int wide,int height) { this(topleft.x,topleft.y,(topleft.x += wide),(topleft.y -= height)); } public static void main(String[] args) { Box2 box0 = new Box2(1,2,3,4); System.out.print(box0.x1+" "+box0.y1+" "+box0.x2+" "+box0.y2); Box2 box1 = new Box2(new Point(1,2),3,4); System.out.print(box1.x1+" "+box1.y1+" "+box1.x2+" "+box1.y2); Box2 box2 = new Box2(new Point(1,2),new Point(3,4)); System.out.print(box2.x1+" "+box2.y1+" "+box2.x2+" "+box2.y2); } }
import java.awt.Point; class Box3 { int x1; int y1; int x2; int y2; Box3(int x,int y,int z,int w) { this.x1 = x; this.y1 = y; this.x2 = z; this.y2 = w; } Box3(Point lefttop,Point bottomright) { this.x1= lefttop.x; this.y1= lefttop.y; this.x2= bottomright.x; this.y2= bottomright.y; } Box3(Point lefttop,int width,int height) {this.x1 = lefttop.x; this.y1 = lefttop.y; this.x2 = lefttop.x + width; this.y2 = lefttop.y - height; } void printBox() { System.out.print(x1+" "+y1+" "+x2+" "+y2+" "); } public static void main (String[] args) { Box3 box3; box3 = new Box3(1,2,3,4); box3.printBox(); box3 = new Box3(new Point(1,2),3,4); box3.printBox(); box3 = new Box3(new Point(1,2),new Point(3,4)); box3.printBox(); } }
import java.awt.Point; class Box4 { int x1; int y1; int x2; int y2; Box4(int x,int y,int z,int w) { this.x1 = x; this.y1 = y; this.x2 = z; this.y2 = w; } Box4(Point lefttop,Point bottomright) { this(lefttop.x,lefttop.y,bottomright.x,bottomright.y); } Box4(Point lefttop,int width,int height) {this(lefttop.x,lefttop.y,lefttop.x += width,lefttop.y -= height); } void printBox() { System.out.print(x1+" "+y1+" "+x2+" "+y2+" "); } public static void main (String[] args) { Box4 box4; box4 = new Box4(1,2,3,4); box4.printBox(); box4 = new Box4(new Point(1,2),3,4); box4.printBox(); box4 = new Box4(new Point(1,2),new Point(3,4)); box4.printBox(); } }
相关文章推荐
- [C#]字符串比较--显示相同[In VS],比较结果却不同
- 有两等长数组A,B,所含元素相同,但顺序不同,只能取得A数组某值和B数组某值进行比较,比较结果为大于,小于,等于,但是不能取得同一数组A或者B中两个数进行比较,也不能取得某数组中的某个值
- 汇编 输入几个数子进行比较 不同条输出不同的结果 三个相同输出2 两个同输出1 不同输出0
- 不同型号处理器的性能比较
- 使用SQL Server 2005 新的语法ROW_NUMBER()进行分页的两种不同方式的性能比较
- Linux环境和Windows环境下一个表达式多项自增或自减运算结果的不同
- 五种不同的 URL 参数解析方法的性能比较
- 四种不同单源最短路径算法性能比较
- mapreduce大规模计算实验结果和性能比较
- COPY Java不同压缩算法的性能比较
- 各种 Java 的序列化库的性能比较测试结果
- HTML散点图(Scatter Plot)的三种不同实现方式性能比较
- Java中不同的并发实现的性能比较
- 通过做减法运算,影响标志寄存器,标志寄存器的相关位记录了比较的结果
- Java不同压缩算法的性能比较
- asp两个数组如何进行比较,剔除相同,保留不同
- 相同代码不同的编译结果
- 【Spring MVC】spring mvc中相同的url请求返回不同的结果
- [SoapUI] 比较两个不同环境下XML格式的Response, 结果不同时设置Test Step的执行状态为失败
- List<T>在搜索和排序时采用不同方法的性能比较