• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

choosing overloading method

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic