• 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

Method Overloading Resolution

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a piece of code


the answer is false and true,I understand but when a call is made
olrRef.testIfon(tlref);,this matches both method at //1 and //2
as reference tlref which denotes the object of class TubeLight,can also
be assigned to a reference of its superclass Light.How does the
Resolution took place plz guide me to understand the concept behind
that.

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The overloaded that is called is determined by the reference type of the argument.

When called with 'lref' (a Light reference) the overloaded method that takes a Light reference is called.

When called with 'tlref' (a TubeLight reference) the overloaded method that takes a TubeLight reference is called.

You can also experiment by passing a Light (superclass reference) to a TubeLight (subclas object) and see that it is the method that takes a Light reference that is called:



Cheers,

Si.
 
deshdeep divakar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks a Lot

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic