For the following program, why are the methods found with the int and string arguments instead of long and object?
wanted to know why the compiler wants to choose long
and string
over object
arguments.
Note: This was asked in an interview.
Public class lawloading tastes {public static zero addition (int n, int m) {System.out.println ("int method"); Println (n + m); } Adding public static void (long n, long m) {System.out.println ("long method"); Println (n + m); } Public static zero method {System.out.println ("string method"); } Public static zero method (object obj) {System.out.println ("Object method"); } / ** * Ultimate Arguments * / Public Stable Zero Main (string [] Args) {add (2,3); Method (zero); }}
for addition (2,3)
In the method, you are passing the integer, this is the reason that the integer is being called for the method (empty)
, the most specific method argument is selected. In this situation, the string
object is more specific than
. Therefore, method (string stat);
becomes.
No comments:
Post a Comment