oop

8. Abstract Classes: Partial Implementation

Analyze the code, write your predicted output, and then reveal the solution.

Scenario

An abstract class provides some common behavior but forces subclasses to implement specific details.

Code Block
abstract class Shape { String color; Shape(String color) { this.color = color; } void describe() { System.out.println("A " + color + " shape"); } abstract double area(); // Must be implemented by subclasses } class Circle extends Shape { double radius; Circle(String color, double radius) { super(color); this.radius = radius; } @Override double area() { return Math.PI * radius * radius; } } public class Main { public static void main(String[] args) { Shape s = new Circle("Red", 5); s.describe(); System.out.println("Area: " + Math.round(s.area())); } }
Take Your Shot
Predicted Output

Type exactly what you think will be printed in the console.

8. Abstract Classes: Partial Implementation | DevExCode