Method calling in java -
this question has answer here:
i have following structure of class:
void add(string s){ system.out.println("string"); } void add(object s){ system.out.println("object"); } public static void main(string[] args) { new myclazz().add(null); }
o/p : string
why object not called?
string
more specific object
. therefore void add(string s)
preferred on void add(object s)
.
15.12.2. compile-time step 2: determine method signature
the second step searches type determined in previous step member methods. step uses name of method , argument expressions locate methods both accessible , applicable, is, declarations can correctly invoked on given arguments.
there may more 1 such method, in case specific 1 chosen. the descriptor (signature plus return type) of specific method 1 used @ run time perform method dispatch.
Comments
Post a Comment