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
- Abstract methods have no body
- Abstract class cannot be instantiated
- Child must implement all abstract methods
Related Inheritance exercises
- Practice Method Overriding in Java
- Practice Using Super Keyword in Java
- Practice Implementing Interface in Java
Practice all Inheritance exercises · Run this idea in the Java compiler