early vs late binding

S

shaun.86

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?
 
R

Roedy Green

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.
 
Q

q_q_anonymous

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top