Interview Question
Country: India
Interview Type: Written Test
It prints string and object with the following code;
public class chckTheStuff {
static void callme(String s) {
System.out.println("string");
}
static void callme(Object s) {
System.out.println("Object");
}
public static void main(String[] args) {
Object ok = null;
callme(null);
callme(ok);
}
}
The most specific function will be called to avoid an ambiguity. Since String and Object references can be both be null, the more specified class is preferred.
- Daniel June 07, 2014