The conversation between human and AI assistant.
Java: What is an interface in Java?
Can you give me an example of when you would use an interface in Java?
One example is when you want to create different implementations of a common operation. For instance, you could create an interface called "Shape" with methods like "calculateArea()" and "calculatePerimeter()". Then you could have different classes like "Circle" and "Square" that implement the Shape interface and provide their own implementation of these methods.