> public class Test {
> public void disp(Object o) {
[quoted text clipped - 10 lines]
>
> the above compiles and displays String Vesion.how it is....explain....
Object is a superclass of String, so although both versions are
applicable, the String version is more specific.
> public class Test {
> public void disp(StringBuffert sb {
[quoted text clipped - 17 lines]
>
> why explain .........
There is no superclass/subclass relationship between String and
StringBuffer, so neither version is more specific than the other.
Patricia
Tom McGlynn - 27 Jan 2008 20:32 GMT
> > public class Test {
> > public void disp(Object o) {
[quoted text clipped - 40 lines]
>
> Patricia
For a little more discussion of this you might take a look at #46 in
Bloch and Gafter's Java Puzzlers. This is in any case a fun book to
read and illuminates many dark nooks and crannies in Java.
Regards,
Tom McGlynn
>the aboce code generates comile time error
> Test.java:10: reference to disp is ambiguous, both method
>disp(java.lang.StringB
>uffer) in Test and method disp(java.lang.String) in Test match
> t.disp(null);
> ^
see
http://mindprod.com/jgloss/compileerrormessages.html#REFERENCEAMBIGUOUS

Signature
Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com