shaun.86 said:
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