我有一个非常简单的课程:
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:\Projects\Development\MyJava\bin\MyDev>"C:\Program Files (x86)\Java\jdk1.7.0_55\bin\javap" -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? 对于我的生活,我无法理解!
答案 0 :(得分:4)
这是对Object
的构造函数的调用。对超类构造函数的调用始终是构造函数中发生的第一件事。