public class NullDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
NullDemo n = new NullDemo();
n.execute(null);
}
public void execute(Object o) {
System.out.println("object");
}
public void execute(Double o) {
System.out.println("double");
}
}
i have executed this above code and it execute the method with execute(Double o).i need to know the reason why it executed execute(Double o) and not execute(Object o)
and suppose
public class NullDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
NullDemo n = new NullDemo();
n.method1(null); /// give the compilation error
}
public void method1(Float o) {
System.out.println("object");
}
public void method1(Double o) {
System.out.println("double");
}
}
if i make the method public void method1(Float o) and public void method1(Double o) it will give the compilation error why this is so? is this related with hierarchy?