← Java Programming learning pathJava Programming · Module 7 of 10
Interfaces and abstract classes
Define contracts with interfaces and partial blueprints with abstract classes.
📖 Key ideas
- An interface lists methods a class promises to implement.
- class Car implements Vehicle, Serializable: a class can implement many interfaces.
- An abstract class cannot be instantiated and can mix implemented and abstract methods.
- Interfaces can have default methods with a body (Java 8+).
- 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