Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

query

 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii

Could anyone plz explain the term latebinding ?
i.e
We can use the same base class refrence to point to diffrent subclasses
but when a overrided method is called the execution depends on the
refrnced object in the garbage.They call it Latebinding ?
How can we say that is runtime binding when the code is written before compiling?
Sorry to ask such a silly question but i am puzzled.

Thanks
Regards
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might have a method that takes an argument defined by an interface:

The List interface has no code at all, so the compiler can't possibly generate a direct call right into a method. So at run time (late) it looks at the actual object instance that is passed into the method, binds your call to the object's size() method and calls it.

The class that defines the object that is passed in might not have a size() method. It might extend another class that does have size(). So you can imagine the JRE working its way up the chain of superclasses until it finds the method. In truth, the compiler and the JVM may optimize this search away, but it's still a valid mental picture.
 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stan James

I understood your point.

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic