Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sample Programs on polymorphism using oops?

Former Member
0 Likes
572

Guys,

I need some sample programs on polymorphism using oops.

If u provide it will be very helpful to me.

<<removed by moderator>>

regards,

vijay

3 REPLIES 3
Read only

Former Member
0 Likes
543

Hi,

Check this examples <b>demo_interface</b>

<b>demo_inheritance</b> in SE38.

Regards

Vijay

Read only

Former Member
0 Likes
543

Hi Vijay,

Polymorphism is the property of OOP whereby it allows one interface to be used for a general class of actions.It means you can ask different objects to perform different implementation in a similar way of calling.

I have also sent u a program on Polymorphism.

Regards,

Sylendra.

Read only

Former Member
0 Likes
543

hi,

its a characteristic of OOPS wher objects fr different class react differently 2 same function call.


Shape.java
public interface Shape{   

  public void draw(){
  }
}


Square.java
class Square implements Shape{  

    public void draw(){
      System.out.println("Drawing a square.....");   
   }
}


circle.java
class Circle implements Shape{    

   public void draw(){
       System.out.println("Drawing a Circle....");    
  }
}


class ShapeGenerator{
Shape shape;

   public void drawSquare() {
    shape=new Square();      
    shape.draw(); 
  }

  public void drawCircle(){
    shape=new Circle();     
    shape.draw();
  }
}

Edited by: Marcelo Ramos on Jan 6, 2009 11:36 AM