What is static binding in Java?

Java 8Object Oriented ProgrammingProgramming

In static binding, the method call is bonded with the method body at compile time. This is also known as early binding. This is done using static, private and, final methods.

Example

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

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

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

Output

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