• 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

Overloading and early binding

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i want to know if overloaded methods in java use early binding or dynamic binding.

some say that every method in java is dynamically bound, unless the method is static or final, no matter if the method is overloaded or not.

and some say that overloaded methods use early binding.

which one is right?
 
Ranch Hand
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you overload a method, what do you see?.

Well you see that the methods have different signature altogether. Like round(int) / round(float) etc!. That means once your code is written, while compilation(or whatever) the compiler will be able to make it out! And so it is and it WILL be Early Binding for sure!

However, when you go for overriding as in cases of inheritance, the compiler validates the method signature but it really can't make it out! And it is only in the run time that the JVM knows which method to pick!..bingo => Late Binding!

Thanks,
Pavan.
 
Oceana Wickramasinghe
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pavan Kumar Dittakavi wrote:When you overload a method, what do you see?.

Well you see that the methods have different signature altogether. Like round(int) / round(float) etc!. That means once your code is written, while compilation(or whatever) the compiler will be able to make it out! And so it is and it WILL be Early Binding for sure!

However, when you go for overriding as in cases of inheritance, the compiler validates the method signature but it really can't make it out! And it is only in the run time that the JVM knows which method to pick!..bingo => Late Binding!

Thanks,
Pavan.



What about this, can the compiler decide which method to call here? Or is it decided at runtime?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the Java™ Language Specification. It is clear about "compile-time".
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course, if you pass null, that is a special case. See if you can work out what happens for a null.

Sorry for the delay in posting this message. I thought I sent it yesterday, and must have forgotten toclick "submit".
reply
    Bookmark Topic Watch Topic
  • New Topic