polymorphism doubt

In the program below , why is it that the seconf testPoly is executed?

public class First {

}

class Second extends First{

}

class Third extends Second{

public static void testPoly(First a,First b){

System.out.println("@@@@@@@@@@@@@@@1");

}

public static void testPoly(First a,Second b){

System.out.println("@@@@@@@@@@@@@@@2");

}

public static void main(String args[]){

Third third = new Third();

testPoly(third,third);

}

}

[525 byte] By [ivinjacoba] at [2007-10-2 19:37:38]
# 1
Because "First, Second" is more specific on the argument type than "First, First" and still matches the arguments provided. if it wouldn't work that way, you could never overload a method that takes an Object reference as an argument, unless you use primitives.
CeciNEstPasUnProgrammeura at 2007-7-13 21:26:09 > top of Java-index,Java Essentials,Java Programming...
# 2
Thnk you , its was a good information for me
ivinjacoba at 2007-7-13 21:26:09 > top of Java-index,Java Essentials,Java Programming...
# 3

A hint: this applies however only to the static (=compile-time) type of the aargument, not its run-time type.

class First {

}

class Second extends First{

}

public class Third extends Second{

public static void testPoly(First a,First b){

System.out.println("@@@@@@@@@@@@@@@1");

}

public static void testPoly(First a,Second b){

System.out.println("@@@@@@@@@@@@@@@2");

}

public static void main(String args[]){

Third third = new Third();

First first = third;

testPoly(third,third);

testPoly(third,first);

}

}

java Third

@@@@@@@@@@@@@@@2

@@@@@@@@@@@@@@@1

BIJ001a at 2007-7-13 21:26:09 > top of Java-index,Java Essentials,Java Programming...
# 4
Don't doubt - just believe!
Dick_Adamsa at 2007-7-13 21:26:09 > top of Java-index,Java Essentials,Java Programming...