Results 1 to 9 of 9
  1. #1
    Navatha is offline Member
    Join Date
    Sep 2010
    Posts
    11
    Rep Power
    0

    Default Dynamic binding vs Polymorphism

    Hi All ,
    Can anyone please explain me the difference between dynamic binding and polymorphism and when do we use them.

    Thanks in Advance
    navatha

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Navatha View Post
    Can anyone please explain me the difference between dynamic binding and polymorphism and when do we use them.
    Is Google down in your part of the world?

    kind regards,

    Jos

  3. #3
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Dynamic Binding is having two objects who are both parented by the same class but are of differing classes. They both have an extension of a method in their parent class, and when it is called ambiguously, either method can be called. Example:
    Java Code:
    public class Human {
    	public void SayHello() {
    		// Empty
    	}
    }
    Java Code:
    public class Man extends Human {
    	@Override
    	public void SayHello() {
    		// Code for a man to say hi
    	}
    }
    Java Code:
    public class Woman extends Human {
    	public void SayHello() {
    		// Code for a woman to say hi
    	}
    }
    Java Code:
    public class SomeOtherClass {
    	@Override
    	public void SomeFunc(Human x) {
    		x.SayHello();
    	}
    }

    This is an example of a situation involving dynamic binding. Notice how the x object passed is a Human, but when SayHello() is called it will select the SayHello() pertinent to the object, be it a Human, Man, or Woman.

    Polymorphism is a broader term that simply allows multiple object types (classes) to be handled by the same interface, such as having both Man and Woman be handled by Human. (Not really an interface in this case, but the same idea.)

    Wikipedia can elaborate further. Best of luck!

  4. #4
    Navatha is offline Member
    Join Date
    Sep 2010
    Posts
    11
    Rep Power
    0

    Default

    thank you zack

  5. #5
    icodeurmom is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Thumbs down Re: Dynamic binding vs Polymorphism

    FYI, why make a forum when people just reply with is "google down?"

    I googled this and ended up here, giving this site more attention, and it might have even been new members. After reading a moderator post a rude comment, I have deflected my interests elsewhere looking for a nicer, more mature community. Kthxbai

    Kind regards,

    ICodeUrMom
    Quote Originally Posted by JosAH View Post
    Is Google down in your part of the world?

    kind regards,

    Jos

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: Dynamic binding vs Polymorphism

    Quote Originally Posted by icodeurmom View Post
    FYI, why make a forum when people just reply with is "google down?"

    I googled this and ended up here, giving this site more attention, and it might have even been new members. After reading a moderator post a rude comment, I have deflected my interests elsewhere looking for a nicer, more mature community. Kthxbai
    Why answer a question that has been asked (and answered) so many times? Google is a better place for that instead of wasting others' time.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    trevMD is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Dynamic binding vs Polymorphism

    well, the answer was partially complete. Dynamic binding occurs during runtime, when the compiler cannot determine the concrete class type (vs static binding)

  8. #8
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: Dynamic binding vs Polymorphism

    I tried it using post#3

    I tried to access
    Java Code:
    SomeFunc()
    using....
    Java Code:
    public static void main(String[] args){
        	 SomeOtherClass a=new SomeOtherClass(); // I'm sorry I edited this recently 
        	 Human h=new Human();
        	a.SomeFunc(h);
        }
    Here, a.SomeFunc(h); and h.SayHello(); are different ?
    which 1 is runtime polymorphism?
    Last edited by noobplus; 07-18-2013 at 03:21 PM. Reason: reply was not clear

  9. #9
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: Dynamic binding vs Polymorphism

    Quote Originally Posted by noobplus View Post
    \
    Here, a.SomeFunc(h); and h.SayHello(); are different ?
    which 1 is runtime polymorphism?
    I got the answer.. a.SomeFunc(h); and h.SayHello(); are same..
    Java Code:
             Human m=new Man();
             a.SomeFunc(m);
        	 Human w=new Woman();
        	a.SomeFunc(w);
    is runtime polymorphism, happens at sametime,
    while,
    Java Code:
    Human h=new Human();
    Human m=new Man();
    this is dynamic binding, both assumptions are possible

Similar Threads

  1. dynamic binding
    By apparao in forum New To Java
    Replies: 1
    Last Post: 02-16-2010, 08:41 AM
  2. Polymorphism Help
    By AWPtic in forum New To Java
    Replies: 5
    Last Post: 04-06-2009, 04:13 PM
  3. Dynamic Binding
    By javarishi in forum New To Java
    Replies: 3
    Last Post: 04-09-2008, 11:17 AM
  4. what is polymorphism
    By Nari in forum New To Java
    Replies: 5
    Last Post: 04-04-2008, 03:14 AM
  5. what's polymorphism?
    By christina in forum New To Java
    Replies: 2
    Last Post: 08-05-2007, 10:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •