Jump to content

Recommended Posts

Posted

Hello Everyone, I'm currently doing an assignment for one of my classes, and in it, I have to give examples, using Java syntax, of  *static*  and  *dynamic binding*. I am lost while understanding the work process.

I understand the basic concept, that static binding happens at compile time and dynamic binding happens at runtime, but I can't figure out how they actually work specifically.

I found an example of static binding online that gives this example and running the program on interviewbit.

public static void callEat(Animal animal) {
    System.out.println("Animal is eating");
}

public static void callEat(Dog dog) {
    System.out.println("Dog is eating");
}

public static void main(String args[])
{
    Animal a = new Dog();
    callEat(a);
}


And that this would print "animal is eating" because  *the call to  `callEat`  uses static binding* , but I'm unsure as to  *why*  this is considered static binding.

So far none of the sources I've seen have managed to explain this in a way that I can follow. Can anyone suggest me?

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines