0% found this document useful (0 votes)
6 views4 pages

pgm5

Uploaded by

happy worker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

pgm5

Uploaded by

happy worker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

class Shape

int a;

Shape()

a=0;

Shape(int a)

this.a=a;

int side()

return(a);

void draw()

System.out.println("Shape is Drawn");

void erase()

System.out.println("Shape is Erased");

class Circle extends Shape

Circle()

super();

Circle(int r)
{

super(r);

void draw()

System.out.println("Circle is drawn with radius =" + side());

void erase()

System.out.println("Circle is Erased");

a=0;

class Triangle extends Shape

int h;

Triangle()

super();

h=0;

Triangle(int b, int h)

super(b);

this.h=h;

void draw()

System.out.println("Triangle is drawn with l=" + side() + ", h="+h);

void erase()
{

System.out.println("Triangle is Erased");

a=h=0;

class Square extends Shape

Square()

super();

Square(int a)

super(a);

void draw()

System.out.println("Square is drawn with side=" + side());

void erase()

System.out.println("Square is Erased");

a=0;

class ShapeDemo

public static void main(String s[])

Circle c1= new Circle(5);

Triangle t1=new Triangle(2,3);


Square s1=new Square(6);

c1.draw();

c1.erase();

t1.draw();

t1.erase();

s1.draw();

s1.erase();

System.out.println("Demostrating Polymorphism through dymanic method dispatch");

Shape sh;

sh=c1;

sh.draw();

sh.erase();

sh=t1;

sh.draw();

sh.erase();

sh=s1;

sh.draw();

sh.erase();

You might also like