Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public abstract class Shape { protected String type; public abstract void draw(); } public class Rectangle extends Shape { public Rectangle() { type=Rectangle; } public

public abstract class Shape { protected String type; public abstract void draw(); } public class Rectangle extends Shape { public Rectangle() { type="Rectangle"; } public void draw() { System.out.println("Draw Shape: " + type); } } Shape[] shapearray = new Shape[20]; int i; // variable to use with loop 
public class Oval extends Shape { public Oval() { type="Oval"; } public void draw() { System.out.println("Draw Shape: " + type); } } public class Diamond extends Shape { public Diamond() { type="Diamond"; } public void draw() { System.out.println("Draw Shape: " + type); } }

Create an object of type Rectangle and assign it to shapearray at index/subscript 0

Create an object of type Oval and assign it to shapearray at index/subscript 1

Create an object of type Diamond and assign it to shapearray at index/subscript 2

Write a for loop from 0 to 2 and use the objects in shapearray to execute the draw() method Do not declare variables, that has been done for you, use variable i with the loop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. Arranging for the training facility and room.

Answered: 1 week ago

Question

1. Discuss the five types of learner outcomes.

Answered: 1 week ago