Dynamic Binding Example in Java

By | December 17, 2010
Dynamic Binding Example in Java. You can find dynamic binding Concept with Example Program (code snippets) in this page.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *