Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Difference between Late binding and Early Binding.  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difference between Late binding and Early Binding. Is there any difference between Dynamic polymor and Late binding. Can anyone give me an example
 
Marshal
Posts: 62199
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't say early binding. Say compile‑time binding or static binding. That will make the concept easier to understand. All static methods are bound at compile‑time in Java®, so if you say…, the compiler will choose which method to use, that in the Animal class, and you will get the same result irrespective of whether you have a dog or a cat. Incidentally, that is why you should call static methods by ClassName.method not objectName.method.
As you will find from this FAQ, static methods always use compile‑time binding. Fields also use compile‑time binding.
For late binding, come back in a few minutes.
 
Campbell Ritchie
Marshal
Posts: 62199
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure you would find something better in Wikipedia or similar.

Don't say late binding. Say runtime binding or dynamic binding. That applies to instance methods, and nothing else. Instance methods can be overridden, but nothing else can be overridden. Instance methods are sought dynamically. The opposite of dynamic is static; things checked at compile‑time are not dynamically bound and that is probably why static methods are called static.At compile time, all that is checked is the existence of a method with that name in the Animal class. That will ensure that Dog and Cat both have a correct version of the method, too. At runtime, there is dynamic binding (see, easier name to understand than late binding) or runtime binding (the name reminds you how it works), and the runtime looks in the associated Class<T> object to look for the method. If it finds it, the method has been overridden and it uses that version. If not, the method has not been overridden and the runtime looks in superclasses' Class<T> objects until it finds the (not overridden) method. That is how polymorphism is implemented. Read more about polymorphism here. Runtime binding means you do not need to know the actual type of the object beforehand:-You will get the correct overriding of that method for a Lion or a Wildebeest even though you do not know which it will be.


Warning: The different types of binding are different for different object‑oriented languages. I think (but I am not sure) that the different kinds of binding apply only to object‑oriented programming.

[edit]: Another warning. What I said has been very much simplified.
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!