class Super
{
void method(Super s1)
{
System.out.println("Super");
}
}
class Sub extends Super
{
void method(Sub sb1)
{
System.out.println("Sub");
}
}
class TestInher
{
public static void main(
String [] args)
{
Super sp1 = new Super();
Sub sb1 = new Sub();
Super spb = new Sub();
spb.method(sp1); //Produces O/P Super "No Doubt in it"
spb.method(sb1); //Produces O/P Super "Why"
spb.method(spb); //Produces O/P Super "No Doubt in it"
}
}
// I thought that it should print "Sub" for second method call...
// Why it prints "Super".....
// When we call method using super class reference and sub type
// object, the method in the sub class should be called... But, here
// Why the super class method is called... Plz explain.....