Java Interface vs Abstract Class: When to Use What

While “the distinction between interfaces and abstract classes” constitutes a common inquiry, investigation beyond superficial differences reveals remarkably diverse perspectives. Java 8’s introduction of default methods in interfaces substantially diminished the distinctions between the two constructs. This exposition examines in detail when each proves most appropriate. Fundamental Characteristics Let us first examine the basic characteristics. Interface May contain constants (static final) and abstract methods 1 2 3 4 interface Barkable { public static final int BLABLA_CONSTANT = 1; public abstract void bark(); } Java 8 introduced default methods (permitting complete implementation) ...

October 24, 2021 · 890 words · Mihyang Gu