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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

mixed variable overloading

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


y1 is a mixed varible.
to what fuction should i put y1
a function f that inputs A variable or B variable
?
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
First, lets add some formatting, as unformatted code is difficult to read...

alex lotel wrote:




alex lotel wrote:
y1 is a mixed varible.
to what fuction should i put y1
a function f that inputs A variable or B variable
?



The overloaded signature to call is determined at compile time, via its reference. And at run time, the overridden method is called based on the actual object type. In your example, at compile time, z1 has the signatures of an A class, so the compiler only knows about the f() method that takes an A instance. And since it refers to a C instance, at run time, it will call the method that takes the A instance, that is declared in the C class.

Henry
 
Henry Wong
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Also, noticed that this topic is a duplicate of this one....

https://coderanch.com/t/590223/java/java/choosing-overloading-method


Please don't post duplicate topics, as it wastes people's time and effort.... and it this case, I guess it wasted my time and effort...

Henry
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic