Learn - Abstract Class vs Interface in Java
Abstract Class vs Interface, Differences, when to use? Why not create an object? Interface Interface is used when you want to define a contract and you don't know anything about implementation. (here it is total abstraction as you don't know anything). Interface is used in a situation, 1. When you know the contract methods but don't know anything about the implementation. 2. Your contract implementation can change in future. 3. You want to achieve dynamic polymorphism and loose coupling that is by just changing one line of code, you should be able to switch between contract implementer. 4. Since multiple inheritance is not supported in Java, you cannot inherit your class from two abstract classes. An interface is your only option in such situations. 5. If there is no default or common behavior among all the classes that are inheriting from abstract class then interface may be a better choice. Example Analogy for point 1: Redbus interface lists out ...