Junior — Middle
What does an interface include in object-oriented programming?
sobes.tech AI
Answer from AI
In object-oriented programming, an interface is an abstract type that defines a set of methods (and sometimes properties) that a class must implement.
It does not contain implementations, only method signatures. This allows for creating flexible and extensible architectures where different classes can have a common contract but different implementations.
Example of an interface in Java:
public interface Drawable {
void draw();
}
public class Circle implements Drawable {
@Override
public void draw() {
System.out.println("Drawing a circle");
}
}
Here, Drawable defines the draw() method, which must be implemented in any class that wants to be "drawable".