Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Java FAQ: Top Questions

13. What are interfaces in Java?

An interface in Java is a blueprint of a class, defining method signatures (and constants) that implementing classes must provide. It supports abstraction and multiple inheritance.

  • Declaration: Defined with the interface keyword.
  • Implementation: Classes implement interfaces using the implements keyword.
  • Methods: Before Java 8, interfaces had only abstract methods (no body). Since Java 8, they can include default and static methods with implementations.
  • Multiple Inheritance: A class can implement multiple interfaces, unlike extending multiple classes.
  • Use Case: Defines contracts for classes (e.g., Comparable , Serializable ).