aspose file tools*
The moose likes Java in General and the fly likes is  it dynamic binding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "is  it dynamic binding?" Watch "is  it dynamic binding?" New topic
Author

is it dynamic binding?

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
hey here is one program


abstract class A
{

abstract void abc();
void xyz(){}
}


class B extends A
{

abstract void abc(){}

}

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
A b =new B();

b.abc(); // IS dynamic binding
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14144
    
  18

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is it dynamic binding?