booleanbRectangleIn(NewRectangle R){ Point p = R.coordinatesLD; if (! bPointIn(p)) { returnfalse; } p = new Point(R.coordinatesLD.x + width, R.coordinatesLD.y + height); if (! bPointIn(p)) { returnfalse; } returntrue; }
booleanbRectangleOverlap(NewRectangle R){ Point p = R.coordinatesLD; if (bPointIn(p)) { returntrue; } p = new Point(R.coordinatesLD.x + width, R.coordinatesLD.y + height); if (bPointIn(p)) { returntrue; } p = new Point(R.coordinatesLD.x, R.coordinatesLD.y + height); if (bPointIn(p)) { returntrue; } p = new Point(R.coordinatesLD.x + width , R.coordinatesLD.y); if (bPointIn(p)) { returntrue; } if (R.bRectangleOverlap(this)) { returntrue; } returnfalse; }
booleanbRectangleIn(NewRectangle R){ Point p = R.coordinatesLD; if (! bPointIn(p)) { returnfalse; } p = new Point(R.coordinatesLD.x + width, R.coordinatesLD.y + height); if (! bPointIn(p)) { returnfalse; } returntrue; }
booleanbRectangleOverlap(NewRectangle R){ Point p = R.coordinatesLD; if (bPointIn(p)) { returntrue; } p = new Point(R.coordinatesLD.x + width, R.coordinatesLD.y + height); if (bPointIn(p)) { returntrue; } p = new Point(R.coordinatesLD.x, R.coordinatesLD.y + height); if (bPointIn(p)) { returntrue; } p = new Point(R.coordinatesLD.x + width , R.coordinatesLD.y); if (bPointIn(p)) { returntrue; } if (R.bRectangleOverlap(this)) { returntrue; } returnfalse; } }
Create new C() in main A(4) A(5) A(3) C() f1(2) Create new C() in main A(3) C() f1(2) Exception in thread "main" java.lang.NullPointerException at StaticInitialization.main(StaticInitialization.java:9)
比较修改之前的输出为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
A(1) A(2) B() f1(1) A(4) A(5) A(3) C() f1(2) Create new C() in main A(3) C() f1(2) Create new C() in main A(3) C() f1(2) f2(1) f3(1)
去掉new B()与new C()
所以以下内容输出缺失:
原始输出
修改后的输出
解释
A(1) A(2) B() f1(1) A(4) A(5) A(3) C() f1(2)
无
去掉new B()与new C(),运行前缺失对 B、C 类装载,所以此部分无输出
Create new C() in main A(3) C() f1(2)
Create new C() in main A(4) A(5) A(3) C() f1(2)
因为 C 此时是第一次装载,故初始化静态成员,输出A(4)、A(5)
Create new C() in main A(3) C() f1(2)
Create new C() in main A(3) C() f1(2)
此部分相同
f2(1) f3(1)
Exception in thread “main” java.lang.NullPointerException at StaticInitialization.main(StaticInitialization.java:9)