What is dynamic binding in Java?

Java 8Object Oriented ProgrammingProgramming

In dynamic binding, the method call is bonded to the method body at runtime. This is also known as late binding. This is done using instance methods.

Example

class Super {
   public void sample() {
      System.out.println("This is the method of super class");
   }
}

Public class extends Super {
   Public static void sample() {
      System.out.println("This is the method of sub class");
   }

   Public static void main(String args[]) {
      new Sub().sample()
   }
}

Output

This is the method of sub class
raja
Published on 02-Jan-2018 07:08:23
Advertisements