java - why does ambiguity not raised for ArithmeticException parameter method -
below code executed out compilation error of ambiguity, , output "arithmeticexception". guys can u me know reason.
class test { public static void main(string[] args) throws unknownhostexception, ioexception { testmetod(null); } // overloaded method of parameter type object private static void testmetod(object object) { system.out.println("object"); } // overloaded method of parameter type exception private static void testmetod(exception e) { system.out.println("exception"); } // overloaded method of parameter type arithmeticexception private static void testmetod(arithmeticexception ae) { system.out.println("arithmeticexception"); } }
in cases rule match specific method. since arithmeticexception extends exception
, arithmeticexception extends object
, there no ambiguity: arithmeticexception
more specific of others.
if add though:
private static void testmetod(string string) { system.out.println("string"); }
you compilation error because neither arithmeticexception extends string
true, nor other way around: there no single specific parameter class.
it's important @ point happening @ compile time. once target method resolved , code compiled, call overloaded method call other method. in contrast method overriding.
Comments
Post a Comment