我有一个非常简单的类:
package MyDev;
public class Point3D {
public Point3D(){x = 0; y = 0;z = 0;}
public float x, y, z;
public Point3D( float X, float Y, float Z )
{
x = X; y = Y; z = Z;
}
}
当我在这个类上运行javap -c
时,我得到的是:
C:ProjectsDevelopmentMyJavabinMyDev>"C:Program Files (x86)Javajdk1.7.0_55binjavap" -c Point3D.class
Compiled from "Point3D.java"
public class MyDev.Point3D {
public float x;
public float y;
public float z;
public MyDev.Point3D();
Code:
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: aload_0
5: fconst_0
6: putfield #14 // Field x:F
9: aload_0
10: fconst_0
11: putfield #16 // Field y:F
14: aload_0
15: fconst_0
16: putfield #18 // Field z:F
19: return
public MyDev.Point3D(float, float, float);
Code:
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: aload_0
5: fload_1
6: putfield #14 // Field x:F
9: aload_0
10: fload_2
11: putfield #16 // Field y:F
14: aload_0
15: fload_3
16: putfield #18 // Field z:F
19: return
}
为什么?为什么第二个构造函数也有签名()V,而不是(FFF)V ?我怎么也搞不懂!
这是对Object
的构造函数的调用。对父类构造函数的调用总是构造函数中发生的第一件事。