Why is this program not calling the sub class method? What is the concept behind it? I'm totally confused with this. Below is the code.
Super class
public class TV {
public void checkType(TV b) {
System.out.println("Its a TV");
}
}
Child class
public class LedTv extends TV {
public void checkType(LedTv b) {
System.out.println("Its a LED TV");
}
}
Test case to get the result
public class TestTV {
public static void main(String argss[]) {
TV a = new TV();
TV b = new LedTv();
a.checkType(a);
b.checkType(b);
}
}
Both of the checkType method prints
Its a TV
Its a TV