0% found this document useful (0 votes)
13 views1 page

Dilan Java

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

Dilan Java

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

class Shape {

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

void erase() {
System.out.println("Erasing a shape");
}
}

class Circle extends Shape {


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

void erase() {
System.out.println("Erasing a circle");
}
}

class Triangle extends Shape {


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

void erase() {
System.out.println("Erasing a triangle");
}
}

class Square extends Shape {


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

void erase() {
System.out.println("Erasing a square");
}
}

public class ShapeDemo {


public static void main(String[] args) {
Shape[] S = new Shape[3];
S[0]=new circle();
S[1]=new Triangle();
S[2]=new Square();
for(Shape Shape:S)
{
Shape.draw();
Shape.erase();
System.out.println();
}
}
}

You might also like