java - Why Object class have static block? -
i want know why object,string etc. have static{} block @ end.what use of static block in object class.
open cmd prompt , type
javap java.lang.object
what looking @ method , field declarations. since static block method, see empty declaration of static-initalizer.
if @ openjdk source code java.lang.object
on line 40, code says
public class object { private static native void registernatives(); static { registernatives(); }
a simple explanation of static block block gets called once, no matter how many objects of type create.
if want more information command line, javap -verbose java.lang.object
outputs this
static {}; descriptor: ()v flags: acc_static code: stack=0, locals=0, args_size=0 0: invokestatic #16 // method registernatives:()v 3: return linenumbertable: line 41: 0 line 42: 3 }
or, less verbose javap -c java.lang.object
static {}; code: 0: invokestatic #16 // method registernatives:()v 3: return
if want read registernatives()
does, can read post.
Comments
Post a Comment