Can someone explain the difference between early and late binding? (ie
- compile time versus run time binding?) What is the difference
between the two and where would it come into play when coding?
Roedy Green - 19 Dec 2005 02:19 GMT
>Can someone explain the difference between early and late binding? (ie
>- compile time versus run time binding?) What is the difference
>between the two and where would it come into play when coding?
It does not normally apply to Java. Binding happens at class load
time, which is fairly late compared with most other languages.
When you use AOT compilation, (see
http://mindprod.com/jgloss/jet.html) some of the binding happens at
compile time. Only the dynamic Class.forName loading is deferred to
class load time.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
q_q_anonymous@yahoo.co.uk - 20 Dec 2005 06:24 GMT
> Can someone explain the difference between early and late binding? (ie
> - compile time versus run time binding?) What is the difference
> between the two and where would it come into play when coding?
"Java uses late-binding to support polymorphism; which means the
decision as to which of the many methods should be used is deferred
until runtime "
"it is Java's use of late-binding which allows you to declare an
object as one type at compile-time but executes based on the actual
type at runtime "
it's to do with
class A {..}
class B Extends A { }
A a = new B();
A is a's comiletime type.
B is a's runtime type
here's where i get rusty-
if you do a.method1(); and method1() is overriden by B, then it'll
run B's
And if method1() is not overriddden in B, then I think it runs in A -
accesses A's field.
i'm not sure about fields.
I think, if you've overridden a field from A, but you haven't
overridden method1() from A, then method1 will run in A and use A's
fields. So, running in A, maybe that's compile-time binding.
I don't know about if it deides at runtime to invoke a method or acess
a field from a compile-time class. whether that's compile time binding
or runtme binding