Interfaces in Java
Interfaces define a set of methods that a class must implement. This allows you to create code that is more flexible and modular.
Example code:
csharp
public interface Drawable {
void draw();
}
public class Circle implements Drawable {
public void draw() {
System.out.println("Drawing a circle.");
}
}
Circle myCircle = new Circle();
myCircle.draw(); // prints "Drawing a circle."
No comments:
Post a Comment