Abstract Methods

Methods without implementation

4 min read

Abstract Methods

Abstract methods declare behavior without implementation and must be implemented by subclasses.

Code Examples

Abstract method implementation

java
1
2abstract class Shape {
3    abstract double area();
4}
5
6class Circle extends Shape {
7    double radius = 5;
8
9    double area() {
10        return Math.PI * radius * radius;
11    }
12}
13          

Use Cases

  • Enforcing contracts
  • Framework extension points

Common Mistakes to Avoid

  • Providing body to abstract method
  • Missing implementation in subclass