group-icon
Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
270 Members
Join this group to post and comment.
AdhikariHarika Reshma
AdhikariHarika Reshma
Computer Science
18 Jan 2019

Explain dynamic binding in java?

Explain in detail.

DHIRAJ LOTLIKAR
DHIRAJ LOTLIKAR
Information Technology
4mos ago

Binding term is used to the linking between method call and method definition. Following is the example for binding,

public class Example{

void D1{

System.out.println(" D1 invoked");

}

void D2{

System.out.println(" D2 invoked");

}

public static void main(String[] args){

Example obj=new example();

obj.D1();

obj.D2();

}

}

In public static void main we have Methods call and void D1 and D2 are method definition and both are combine which is called binding.

When compiler is not able to resolve the binding at  the compile time. It is also called late binding. Dynamic binding happens during run time. The example of dynamic binding is method overriding.

class Animal{
void eat(){System.out.println("animal is eating...");}
}

class Dog extends Animal{
 void eat(){System.out.println("dog is eating...");}

 public static void main(String args[]){
Animal a=new Dog();
a.eat();
}
}

AdhikariHarika Reshma
AdhikariHarika Reshma
Computer Science
4mos ago

Thank you for explaining in simple way.

Shruthi Pillai
Shruthi Pillai
Information Technology
4mos ago

Dynamic binding occurs during  runtime. Overriding is a perfect example of dynamic binding. In overriding both parent and child classes have same method