How are ambigous methods resolved in java ?
Posted
by Jijoy
on Stack Overflow
See other posts from Stack Overflow
or by Jijoy
Published on 2010-04-09T14:50:00Z
Indexed on
2010/04/09
15:03 UTC
Read the original article
Hit count: 201
java
Hi,
I have a question.
package org.study.algos;
public class Study {
public static void main(String[] args) {
A a = new A();
a.m1(null);
}
}
class A {
public void m1(String s) {
System.out.println("String");
System.out.println(s);
}
public void m1(Object obj) {
System.out.println("Object");
System.out.println(obj);
}
}
Here, the output is
String null
Why does the JVM resolve the method to one with a String argument?
Thanks in advance J
© Stack Overflow or respective owner