Complete the code to declare a method that all shapes can use.
public abstract class Shape { public abstract void [1](); }
The method draw is commonly used to represent drawing a shape. Declaring it abstract means all subclasses must provide their own version.
Complete the code to override the draw method in Circle class.
public class Circle extends Shape { @Override public void [1]() { System.out.println("Drawing a circle"); } }
The draw method overrides the abstract method in Shape to provide specific behavior for Circle.
Fix the error in the code to call the draw method polymorphically.
Shape shape = new Circle();
shape.[1]();Calling draw() on the Shape reference will invoke the Circle's overridden method due to polymorphism.
Fill both blanks to create a list of shapes and call draw on each.
List<[1]> shapes = new ArrayList<>(); shapes.add(new Circle()); for ([2] shape : shapes) { shape.draw(); }
Using the base class Shape for the list and loop variable allows polymorphic calls to draw() on any subclass.
Fill all four blanks to demonstrate polymorphism with different shapes.
Shape [1] = new Circle(); Shape [2] = new Rectangle(); [3].draw(); [4].draw();
Using different variable names for shapes allows calling draw() polymorphically on each specific shape instance.