Abstract Class vs Interface
50 min · Intermediate
An abstract class is a partly built class that holds shared state and code for closely related subclasses. An interface is a contract of capabilities that any class can sign, as many times as it likes. Interviewers want the differences, the Java 8 and 9 interface features, and a clear reason for choosing one.
Topics in this lesson
- Comparison: state, constructors, inheritance, access
- default, static and private interface methods
- Diamond conflict with two default methods
- When to choose which: the payment example
- Functional and marker interfaces
Interview questions this lesson answers
- What is an abstract class?
- What is an interface?
- What is the difference between an abstract class and an interface?
- Can we create an object of an abstract class?
- Can an abstract class have a constructor?
- Can an interface have a constructor?
- What are the default modifiers of interface members?
- Can an interface have instance variables?
- Can an abstract class have no abstract methods?
- If a class has an abstract method, must the class be abstract?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.