If there are several overloaded methods that might be called with a given parameter (null
in your case) the compiler chooses the most specific one.
See http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.2.5
In your case methodTest(Exception e)
is more specific than methodTest(Object e)
, since Exception is a subclass of Object. And methodTest(NullPointerException e)
is even more specific.
If you replace NullPointerException with another subclass of Exception, the compiler will choose that one.
On the other hand, if you make an additional method like testMethod(IllegalArgumentException e)
the compiler will throw an error, since it doesn't know which one to choose.