Abstraction, Abstract Classes and Interfaces
Abstraction means showing a simple contract (a promise of what something does) and hiding how it is done. In Java the main tools are the abstract class (a class, which is a blueprint for objects, that cannot be created directly) and the interface (a list of things a class promises to do). Interviewers ask when to use which, whether an interface can hold code, and what happens when two default methods (methods with a ready-made body inside an interface) clash.
After this section you can define each, choose between an abstract class and an interface, and fix a clash between two default methods.
Topics in this section
- Abstraction as a contract
- Abstract classes
- Interfaces
- One parent class, many interfaces
- Abstract class or interface
- When two default methods clash
- Functional interface