• Post Reply Bookmark Topic Watch Topic
  • New Topic

early and late binding  RSS feed

 
alec stewart stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all java experts
i am kinda new in java.So it well helpful if you can explain clearly what is early binding and what is late binding.
thanks
regards
 
Bill Cruise
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Early binding is when the compiler chooses a method to call at compile time (obviously). This is the only way to do it in true procedural languages like C. Late binding is when the method to call is chosen at run time based on the type of the object.

Say, for example you have classes Employee and Customer in your program and they both override the toString() method. Say also that you have the following reference:

Object obj;

Now, obj can refer to any kind of object. if I have the line of code

obj.toString();

The obj reference might point to an Employee or a Customer based on which one a user selects. The compiler doesn't know which toString() method to call. It has to defer that decision until runtime. This is late binding.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!