Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started