Abstract Classes in Java: Explanation & Practice

Create and implement abstract class

Problem summary

Create an abstract Shape class with abstract area() method, implemented by Circle.

Starter code

// Create abstract Shape with:
// - abstract double area()

// Create Circle extending Shape:
// - double radius
// - implement area()

public class Main {
    public static void main(String[] args) {
        // Create circle radius 5, print area
    }
}

Expected output and test cases

  • Circle area
    Area: 78.54

Hints

  1. Abstract methods have no body
  2. Abstract class cannot be instantiated
  3. Child must implement all abstract methods

Related Inheritance exercises

Practice all Inheritance exercises · Run this idea in the Java compiler