Why is it called dynamic binding?-Collection of common programming errors

The difference between static binding and dynamic binding is that static binding is defined at compile-time – which means that no matter what type of object, it will always call the same member function from whatever class the compiler determines is right, and dynamic binding (or runtime binding) is defined when the code is running. Meaning that the compiler has generated code that will “pick” the corresponding function as the code is being executed, based on what class it belongs to.

The object obviously needs to be COMPATIBLE, but the compiler doesn’t have to know EXACTLY which class the object is during the compilation. Imagine that we have a program that can read a “shape, centre point and size” from a file, where size is just a “1-5” for extra small to extra large, and a function that can create an object of the class square, circle or triangle. Now feed it this:

Square 300, 300, 5
Circle 120, 300, 2
Circle 240, 300, 2
Triangle 300, 300, 1

Of course, the compiler won’t know if you want to make a square, circle or triangle, or what order they come in. And the virtual “draw” function for each of the shapes is obviously different.

That may (if coordinates match up) draw something that sort of looks like a face (well, two eyes and a nose in a square at least).