• Post Reply Bookmark Topic Watch Topic
  • New Topic

choosing overloading method  RSS feed

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



why the outpout is false??
y1 will use the method f from B .because B is the son of A and they both have f
further more the father doesnt have a method f wich recieves B type variable
y2.num=10
y1.num=10
and they are equla
 
Karthikayini Devi
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,

Since you are calling a OVERLOADED method, compiler will look for the reference type only and not the instance type.
You are invoking the method f using class A's reference variable. And A knows only f(A a). At runtime you can pass a covariant i.e, you can pass B's instance to f(A a).
y1.f(y2) will invoke A's f(A,a) method. Hence you are getting false obviously.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!