class Test{ public static void main(String args[]) { B b =new B();
b.abc(); b.xyz();//DYNAMIC BINDING } }
so yesterday one senior software is saying that by calling b.xyz(); the concept is dynamic binding
but i told him that it is a inheritence concept but he is not satisfied at my answer
how can it be a dynamic binding here when i am calling the method b.xyz(); it will be checked at compile time ot at runtime am i right ???
please tell me your views
A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Ajay Singh
Ranch Hand
Joined: Dec 13, 2006
Posts: 182
posted
0
A b =new B();
b.abc(); // IS dynamic binding
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
The language *is* using dynamic binding to call the method, even though it wouldn't be necessary in this special case.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
so yesterday one senior software is saying that by calling b.xyz(); the concept is dynamic binding
but i told him that it is a inheritence concept but he is not satisfied at my answer
You make it sound as if these are two mutually exclusive concepts. They are not. Ofcourse your example code involves inheritance. Java uses dynamic binding to find out which version of a method to call - the version in the superclass or the version in the subclass.
If you do this:
B object = new B(); object.xyz();
then dynamic binding is not really necessary, because the compile-time type of the object is the same as the dynamic (runtime) type of the object. However, if you do this:
A object = new B(); object.xyz();
then the compile-time type of the object (A) is different from the dynamic type (B) - and Java has to determine at runtime (not at compile time) that it should call method xyz() in class B instead of class A. That's dynamic binding.