CHAPTER 18
Beginner
Interfaces and Abstract Classes
Updated: May 17, 2026
5 min read
# CHAPTER 18
Interfaces and Abstract Classes
1. Introduction
Interfaces define a contract — a set of method signatures that a class promises to implement. They are Java's answer to multiple inheritance, allowing a class to implement multiple interfaces while avoiding the diamond problem.2. Defining and Implementing Interfaces
java
3. Default Methods (Java 8+)
Interfaces can have methods with implementations:
java
4. Static Methods in Interfaces
java
5. Functional Interfaces (Java 8+)
An interface with exactly ONE abstract method — usable with Lambda expressions:
java
6. Interface vs Abstract Class
| Feature | Interface | Abstract Class |
|---|---|---|
| Methods | Abstract + default/static | Abstract + concrete |
| Variables | public static final only | Any type |
| Constructor | No | Yes |
| Multiple inheritance | Yes | No |
extends or implements | implements | extends |
7. MCQ Quiz with Answers
Question 1
Which keyword implements an interface?
Question 2
Can a class implement multiple interfaces?
Question 3
Interface variables are implicitly:
Question 4
A functional interface has:
Question 5
Can interfaces have constructors?
Question 6
Default methods were added in Java:
Question 7
An interface method is implicitly:
Question 8
Can an abstract class implement an interface?
Question 9
@FunctionalInterface is:
Question 10
Which allows multiple inheritance in Java?
8. Interview Questions
- Q: When would you use an interface vs an abstract class?
- Q: What is a marker interface (e.g., Serializable)?
- Q: Can an interface extend another interface?
- Q: What are default methods and why were they added in Java 8?