A class adopts an interface by using the implements keyword. Once it does, it must provide a concrete body for every method the interface declares. If you forget even method, the compiler rejects your code.
class Circle implements Drawable {
double radius;
Circle(double radius) {
this.radius = radius;
}
public void draw() {
System.out.println("Drawing circle");
}
public double area() {
return Math.PI * radius * radius;
}
}
The public modifier on each method is required. Interface methods are public by contract, and Java won't let you reduce visibility when you implement them.