← Java Programming learning path
Java Programming · Module 7 of 10

Interfaces and abstract classes

Define contracts with interfaces and partial blueprints with abstract classes.

📖 Key ideas

  1. An interface lists methods a class promises to implement.
  2. class Car implements Vehicle, Serializable: a class can implement many interfaces.
  3. An abstract class cannot be instantiated and can mix implemented and abstract methods.
  4. Interfaces can have default methods with a body (Java 8+).
  5. Program to interfaces: List<String> list = new ArrayList<>();
💡 Real-life example: An interface is a job description; any person (class) who meets it can take the job.
interfaceContract of methods
implementsFulfils an interface
abstract classClass that cannot be instantiated
default methodInterface method with a body