aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method conversion question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method conversion question" Watch "method conversion question" New topic
Author

method conversion question

Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
The following question is from Dan's mock exam.

I thought static void m(A x, C y) method is the more specific one.So my expected answer was AC.
It gives compiler error.why?Isn't static void m(A x,C y) method most specific one?
Thanks
Veena


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
John Zoetebier
Ranch Hand

Joined: Mar 28, 2003
Posts: 76
The compiler says:

reference to m is ambiguous,
both method m(B,B) in C
and method m(A,C) in C match

1. Class C extends B => C IS_A B
2. Class B extends A => B IS_A A
And because operator IS_A is transitief it follows from 1 and 2 that: C IS_A A
We now know that object c can be passed to m(B,B) or m(A,C)
Can (B,B) be passed on to (A,C): no, because B not IS_A C
Can (A,C) be passed on to (B,B): no, because A not IS_A B
Conclusion: m(B,B) is not more specific than m(A,C)
BTW: all methods are in 1 class.
If methods from a superclass class are overloaded the rules involve the classes as well.
See other posting for this subject.
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Thanks John,I got it .
[ April 29, 2003: Message edited by: Veena Point ]
 
wood burning stoves
 
subject: method conversion question