0 votes
in JAVA by
What is the difference between static binding and dynamic binding?

1 Answer

0 votes
by

In case of the static binding, the type of the object is determined at compile-time whereas, in the dynamic binding, the type of the object is determined at runtime.

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

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

 }  

}  

Related questions

+1 vote
asked Jan 27, 2020 in JAVA by rahuljain1
+1 vote
asked Nov 25, 2021 in Salesforce by DavidAnderson
...