Dynamic Binding Example in Java. You can find dynamic binding Concept with Example Program (code snippets) in this page.
class Shape{
public void draw() {
System.out.println(“\n\tDrawing a shape.”);
}
}
class Circle extends Shape{
public void draw() {
System.out.println(“\n\tDrawing a Circle.”);
}
}
class Rectangle extends Shape{
public void draw() {
System.out.println(“\n\tDrawing a Rectangle.”);
}
}
public class DynamicBindingDemo{
public static void main(String args[]) {
Shape obj;
obj = new Shape();
obj.draw();
obj = new Circle();
obj.draw();
obj = new Rectangle();
obj.draw();
}
}
Result:
Drawing a shape.
Drawing a Circle.
Drawing a Rectangle.