Please enable JavaScript to use CodeHS

CodeHS Glossary


Dynamic Binding Java

Also called late binding, this refers to Java choosing the proper method to call at run time, as opposed to at compile time. For example, suppose Rectangle and Circle both extend the class Shape: ``` Shape rect = new Rectangle(10, 20); Shape circ = new Circle(30); // Rectangle's version of getArea will be called double area1 = rect.getArea(); // Circle's version of getArea will be called double area2 = circ.getArea(); ``` The proper version of `getArea` ends up being called, because it is decided at run time. This is dynamic binding. If it were decided at compile time, then Shape's version of `getArea` would be called, because at compile time the object type is Shape. But we want the more specific version (Circle or Rectangle's version of `getArea`), depending on the type of the object at run time.