Static binding example
Static binding: Static binding or early binding is a case where compiler can resolve
the binding at the compile time only. All static methods are called or accessed using their
respective class names and a compiler can resolve the binding at the compile time. Hence
all static method calls are examples of static binding. Overloaded methods are bonded using
static binding. Below program is an example of "static" binding.
package com.ram; class Addition{ public void add(int a, int b){ System.out.println(a + b); } public void add(String a, String b){ System.out.println(a + b); } } public class StaticBindingExample { public static void main(String[] args) { Addition obj1 = new Addition(); obj1.add("Ram", "Akunuru"); obj1.add(1, 2); } }
Execute StaticBindingExample class and you get the below output:
RamAkunuru
3
RamAkunuru
3
No comments:
Post a Comment