• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method conversion question

 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
John Zoetebier
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John,I got it .
[ April 29, 2003: Message edited by: Veena Point ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic