Late Binding in Java

前端 未结 5 748
不知归路
不知归路 2020-12-16 19:14

I have searched through all the similar questions on late binding on stack overflow, and I would severely disagree with anyone who marks this question as a duplicate. First

5条回答
  •  无人及你
    2020-12-16 19:49

    Consider the statement

     A ref; //reference of A
       ref = new B();//Object of B
          ref.f2();
    

    Here ref is a reference of class A and it has address of object of class B f2() is a overridden method.

    When compiler detects such a statement then it doesn't bind the function call with any definition. It only validates the call.

    Binding of such calls is left for the runtime environment. At program runtime system identifies the datatype of the object and binds the function call with the function definition provided by the class of object. This type of binding between the function call and function defination is called as "late binding" or "runtime binding" or "runtime polymorphism" or "dynamic method dispatch".

    go through this question and read my answer example is also given there.

提交回复
热议问题