---
title: "What is the difference between static binding and dynamic binding in java?"  
description: "What is the difference between static binding and dynamic binding in java?"  
author: "Samuel Fernandes"  
published: 2015-04-02  
updated: 2020-09-21  
canonical: https://www.mindstick.com/interview/2391/what-is-the-difference-between-static-binding-and-dynamic-binding-in-java  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# What is the difference between static binding and dynamic binding in java?

**Static binding:**When type of the object is determined at compiled time(by the compiler), it is known as static binding.\
If there is any private, final or static method in a class, there is static binding.\

```
class Dog{   private void eat(){System.out.println("dog is eating...");}     public static void main(String args[]){    Dog d1=new Dog();    d1.eat();   }  } 
```

\
**Dynamic Binding**When type of the object is determined at run-time, it is known as dynamic binding.\

```
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();   }  }
```

\
Output:dog is eating...\
Here object type cannot be determined by the compiler, because the instance of\
Dog is also an instance of Animal.So compiler doesn't know its type, only its base \
type.

## Answers

### Answer by Anonymous User

**Static binding:**When type of the object is determined at compiled time(by the compiler), it is known as static binding.\
If there is any private, final or static method in a class, there is static binding.\

```
class Dog{   private void eat(){System.out.println("dog is eating...");}     public static void main(String args[]){    Dog d1=new Dog();    d1.eat();   }  } 
```

\
**Dynamic Binding**When type of the object is determined at run-time, it is known as dynamic binding.\

```
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();   }  }
```

\
Output:dog is eating...\
Here object type cannot be determined by the compiler, because the instance of\
Dog is also an instance of Animal.So compiler doesn't know its type, only its base \
type.


---

Original Source: https://www.mindstick.com/interview/2391/what-is-the-difference-between-static-binding-and-dynamic-binding-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
