This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
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

Static Binding vs Dynamic Binding  RSS feed

 
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please tell me if am wrong.

Dynamic binding is runtime polymorphism and static binding is compile time polymorphism right?

Dynamic binding example would be overriding (Methods are invoked based on object of a class)
Static binding example would be overloading (Methods are invoked based on reference type of a class)

Am I correct guys?

Thanks.
 
author and iconoclast
Posts: 24203
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Compile time polymorphism" is another word I hate. Resolving overloaded methods is not polymorphism. Method signatures include their argument types, and so overloaded methods are distinguished at compile time just as if they had different names. "Compile-time polymorphism" makes it sound as if something more is happening, but it's not. Please don't use this term.

Your examples of "dynamic binding" and "static binding" are perfect, though.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Ernest. Thanks for your reply.
[ September 01, 2008: Message edited by: Arjun Reddy ]
 
Marshal
Posts: 62206
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sort of, . . . y-e-e-e-s . . . well, mostly.

It sounds right, but not precise.

Dynamic binding means the runtime finds the type of an object (probably from its Class<T> object) and uses that type to look for the types of methods invoked. As you imply, that applies to overridden class members. And the only kind of class member you can override is an instance method.

Static binding means the compiler finds the type of an object from the declaration of its reference and uses that type to look for the types of members. That applies to non-overridden class members, ie static fields and methods. I am not sure whether it applies to instance fields; can't remember offhand, but you oughtn't make non-constant fields visible outside their class in the first place.

I don't think any of this applies to overloading.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there are classes as follows
Class A{
int num = 10;
int get(){
return num;
}
}

Class B extends A
{
int num = 20;
int get(){
return num;
}
}
A a = new A();
A a1 = new B();

Static Binding: Static / Early binding is compile time binding. It means at compile time jvm decides which class member or method is preferred to call.
e.g.
a.num will be 10 and
a1.num will be 10

Dynamic binding : Late binding si run time binding. At run time jvm decides which method to call, depending on object type. In this case
a.get() will return 10
a1.get() will return 20
 
Campbell Ritchie
Marshal
Posts: 62206
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
machines help you to do more, but experience less. Experience 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!