Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Early BInding & Late BInding

  Asked By: Fern    Date: May 16    Category: Java    Views: 14208
  

Please help me with the Early & Late Binding

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Sean Grant     Answered On: May 16

Early binding  & late  Binding is a concept of OOPS..B'coz the data and the method
which will operate on data are sepertaely defined in oops(called abstraction
).And they will bind data members and methods either at the complie time or
runtime time. This is called encapsulation.

In early binding the data and method are binds at the complie time where as in
late binding the data and method will bind at the runtime.

 
Answer #2    Answered By: Huette Miller     Answered On: May 16

hope following example helps you .........

class A
{
public void foo()
{
System.out.println("Class A");
}
}

class B extends A
{
public void foo()
{
System.out.println("Class B");
}
}


public class C
{
public static void main(String [] args)
{
A a=new A();
B b=new B();
A ref=null;

a.foo(); // early binding  --- calls method foo() of class A ....
decided at compile time
b.foo(); // early binding --- calls method foo() of class B ....
decided at compile time


ref=b;
ref.foo(); // late  binding --- --- calls method foo() of class B
.... decided at Run time
}

}

 
Answer #3    Answered By: Maria Miller     Answered On: May 16

Well early and late binding  is a good concept, well consider a situation where
you have a class with a method, now you call the method in your main method
using the object of the class, in this situation the complier knows which method
to call before execution, this is early binding..

eg
class Earlybinding{
void EarlyHello()
{
System.out.println("Hello Early binding...");
}
public static void main(String args[]){
Earlybinding ob = new Earlybinding();
ob.EarlyHello();
}
}


In late  binding the complier doesn't know which method to call during complie
time, the method call is resolved only during runtime... this can be achived in
inheritance or by using an interface

eg
public interface LateBinding{
void meth1();
void meth2();
}

class LateBind implements LateBiding{
public static void main(String args[]){
// create a reference of the interface
// make sure to set the classpath appropriately
LateBinding ref;
// The following method invocation is resolved only during run-time this is an
example of
//late binding
ref.meth1();
ref.meth2();
}
}

 
Answer #4    Answered By: Sudhakar Chavali     Answered On: Feb 10

I have a question

Can we consider below code as part of Late binding?

import java.lang.reflect.*;
public class Main
{
public static void main(String[] array) throws Exception
{
Class c= Class.forName("Child");
Method m=c.getMethod("test", String[].class);
Object t = c.newInstance();
Object o= m.invoke(t, new Object[]{array});
}
}

class Child extends Main
{
public void test(String[] array)
{
System.out.print("Hello Java World!!!");
}
}

 
Didn't find what you were looking for? Find more on Early BInding & Late BInding Or get search suggestion and latest updates.




Tagged: