I have two sample program to understand parameter casting in Java.
Program 1:
public class TestRunner {
public static void main(String[] args) {
TestRunner r = new TestRunner();
r.call(null);
}
void call(Object obj){
System.out.println("I am from object");
}
void call(String obj){
System.out.println("I am from string");
}
}
Program 2:
public class TestRunner {
public static void main(String[] args) {
TestRunner r = new TestRunner();
r.call(null);
}
void call(Object obj){
System.out.println("I am from object");
}
void call(String obj){
System.out.println("I am from string");
}
void call(Integer obj){
System.out.println("I am from Integer");
}
}
Program 1 prints "I am from string" Program 2 giving compilation error.
Please Explain me how its work.